-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/*! | ||
* @license | ||
* Copyright (C) 2021 Final Hill LLC | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
* @see <https://spdx.org/licenses/AGPL-3.0-only.html> | ||
*/ | ||
|
||
/** | ||
* Biconditional. | ||
* p ↔ q. | ||
* "P if and only if Q". | ||
* An example of usage is the encoding of "You can ride the train if and only if you have a ticket" | ||
* This is logically equivalent to: implies(p,q) && implies(q,p) | ||
* | ||
* @example | ||
* iff(person.hasTicket, person.ridesTrain) | ||
* | ||
* @param {boolean} p - The antecedent | ||
* @param {boolean} q - The consequent | ||
* @returns {boolean} - The result | ||
*/ | ||
export default function iff(p: boolean, q: boolean): boolean { | ||
return (p && q) || (!p && !q); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/*! | ||
* @license | ||
* Copyright (C) 2021 Final Hill LLC | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
* @see <https://spdx.org/licenses/AGPL-3.0-only.html> | ||
*/ | ||
import iff from '../iff'; | ||
|
||
// https://github.com/final-hill/decorator-contracts/issues/225 | ||
describe('Biconditional tests', () => { | ||
test('Truth Table', () => { | ||
/* | ||
p q p ↔ q | ||
--------------- | ||
T T T | ||
T F F | ||
F T F | ||
F F T | ||
*/ | ||
expect(iff(true,true)).toBe(true); | ||
expect(iff(true,false)).toBe(false); | ||
expect(iff(false,true)).toBe(false); | ||
expect(iff(false,false)).toBe(true); | ||
}); | ||
}); |