| Total Complexity | 13 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | OPERATION_NAMES = ( |
||
| 2 | "conjunction", |
||
| 3 | "disjunction", |
||
| 4 | "implication", |
||
| 5 | "exclusive", |
||
| 6 | "equivalence", |
||
| 7 | ) |
||
| 8 | |||
| 9 | |||
| 10 | def boolean(x, y, operation): |
||
| 11 | if operation == 'conjunction': |
||
| 12 | if x and y: |
||
| 13 | return 1 |
||
| 14 | else: |
||
| 15 | return 0 |
||
| 16 | elif operation == 'disjunction': |
||
| 17 | if x or y: |
||
| 18 | return 1 |
||
| 19 | else: |
||
| 20 | return 0 |
||
| 21 | elif operation == 'implication': |
||
| 22 | if x: |
||
| 23 | return y |
||
| 24 | else: |
||
| 25 | return 1 |
||
| 26 | elif operation == 'exclusive': |
||
| 27 | if x == y: |
||
| 28 | return 0 |
||
| 29 | else: |
||
| 30 | return 1 |
||
| 31 | elif operation == 'equivalence': |
||
| 32 | if x == y: |
||
| 33 | return 1 |
||
| 34 | else: |
||
| 35 | return 0 |
||
| 36 | |||
| 37 | |||
| 38 | if __name__ == '__main__': # pragma: no cover |
||
| 39 | # These "asserts" using only for self-checking and not necessary for |
||
| 40 | # auto-testing |
||
| 41 | assert boolean(1, 0, "conjunction") == 0, "and" |
||
| 42 | assert boolean(1, 0, "disjunction") == 1, "or" |
||
| 43 | assert boolean(1, 1, "implication") == 1, "material" |
||
| 44 | assert boolean(0, 1, "exclusive") == 1, "xor" |
||
| 45 | assert boolean(0, 1, "equivalence") == 0, "same?" |
||
| 46 |