From e5dae59ceaf2996c47566063e883c88a188a1092 Mon Sep 17 00:00:00 2001 From: vansh kabra Date: Fri, 11 Oct 2024 15:04:09 +0530 Subject: [PATCH 01/14] Add algo for BooleanGateslogic --- .../bitmanipulation/BooleanAlgebraGates.java | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/main/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGates.java diff --git a/src/main/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGates.java b/src/main/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGates.java new file mode 100644 index 000000000000..eccdd842f3fc --- /dev/null +++ b/src/main/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGates.java @@ -0,0 +1,106 @@ +package com.thealgorithms.bitmanipulation; + +import java.util.List; + +/** + * Implements various Boolean algebra gates (AND, OR, NOT, XOR, NAND, NOR) + * using Java, generalized to handle multiple inputs. + */ +public final class BooleanAlgebraGates { + + private BooleanAlgebraGates() { + // Private constructor to prevent instantiation + } + + /** + * Interface representing a Boolean gate that takes multiple inputs and returns a result. + */ + interface BooleanGate { + boolean evaluate(List inputs); + } + + /** + * AND Gate implementation. + * Returns true if all inputs are true, otherwise false. + */ + static class ANDGate implements BooleanGate { + @Override + public boolean evaluate(List inputs) { + for (boolean input : inputs) { + if (!input) { + return false; + } + } + return true; + } + } + + /** + * OR Gate implementation. + * Returns true if at least one input is true, otherwise false. + */ + static class ORGate implements BooleanGate { + @Override + public boolean evaluate(List inputs) { + for (boolean input : inputs) { + if (input) { + return true; + } + } + return false; + } + } + + /** + * NOT Gate implementation (Unary operation). + * Only accepts a single input and returns the negation. + */ + static class NOTGate { + /** + * Evaluates the negation of a single input. + * + * @param input The input value to be negated. + * @return The negation of the input. + */ + public boolean evaluate(boolean input) { + return !input; + } + } + + /** + * XOR Gate implementation. + * Returns true if an odd number of inputs are true, otherwise false. + */ + static class XORGate implements BooleanGate { + @Override + public boolean evaluate(List inputs) { + boolean result = false; + for (boolean input : inputs) { + result ^= input; + } + return result; + } + } + + /** + * NAND Gate implementation. + * Returns true if at least one input is false, otherwise false. + */ + static class NANDGate implements BooleanGate { + @Override + public boolean evaluate(List inputs) { + return !new ANDGate().evaluate(inputs); // Equivalent to negation of AND + } + } + + /** + * NOR Gate implementation. + * Returns true if all inputs are false, otherwise false. + */ + static class NORGate implements BooleanGate { + @Override + public boolean evaluate(List inputs) { + return !new ORGate().evaluate(inputs); // Equivalent to negation of OR + } + } +} From 5dfa700fa820b9c999acdda6ff7e2845a66f3fa0 Mon Sep 17 00:00:00 2001 From: vansh kabra Date: Fri, 11 Oct 2024 21:46:24 +0530 Subject: [PATCH 02/14] Add algo for BooleanGateslogic and test cases --- .../bitmanipulation/BooleanAlgebraGates.java | 272 ++++++++++++------ 1 file changed, 190 insertions(+), 82 deletions(-) diff --git a/src/main/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGates.java b/src/main/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGates.java index eccdd842f3fc..15be881d2b38 100644 --- a/src/main/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGates.java +++ b/src/main/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGates.java @@ -1,106 +1,214 @@ -package com.thealgorithms.bitmanipulation; + package com.thealgorithms.bitmanipulation; -import java.util.List; - -/** - * Implements various Boolean algebra gates (AND, OR, NOT, XOR, NAND, NOR) - * using Java, generalized to handle multiple inputs. - */ -public final class BooleanAlgebraGates { - - private BooleanAlgebraGates() { - // Private constructor to prevent instantiation - } + import java.util.List; /** - * Interface representing a Boolean gate that takes multiple inputs and returns a result. + * Implements various Boolean algebra gates (AND, OR, NOT, XOR, NAND, NOR) */ - interface BooleanGate { - boolean evaluate(List inputs); - } + public final class BooleanAlgebraGates { - /** - * AND Gate implementation. - * Returns true if all inputs are true, otherwise false. - */ - static class ANDGate implements BooleanGate { - @Override - public boolean evaluate(List inputs) { - for (boolean input : inputs) { - if (!input) { - return false; + private BooleanAlgebraGates() { + // Private constructor to prevent instantiation + } + + /** + * Interface representing a Boolean gate that takes multiple inputs and returns a result. + */ + interface BooleanGate { + boolean evaluate(List inputs); + } + + /** + * AND Gate implementation. + * Returns true if all inputs are true, otherwise false. + * + * Test cases for AND Gate: + * + * AND([true, true]) should return true. + * AND([true, false]) should return false. + * AND([false, false]) should return false. + * + * Multiple inputs: + * AND([true, true, true]) should return true. + * AND([true, false, true]) should return false. + * + * Edge case (empty input list): + * AND([]) can either return true (since the conjunction of no values + * is true in some interpretations) or throw an exception depending + * your design. + */ + + static class ANDGate implements BooleanGate { + @Override + public boolean evaluate(List inputs) { + for (boolean input : inputs) { + if (!input) { + return false; + } } + return true; } - return true; } - } - /** - * OR Gate implementation. - * Returns true if at least one input is true, otherwise false. - */ - static class ORGate implements BooleanGate { - @Override - public boolean evaluate(List inputs) { - for (boolean input : inputs) { - if (input) { - return true; + /** + * OR Gate implementation. + * Returns true if at least one input is true, otherwise false. + * + * Test cases for OR Gate: + * + * OR([true, false]) should return true. + * OR([false, false]) should return false. + * + * Multiple inputs: + * OR([true, true, false]) should return true. + * OR([false, false, false]) should return false. + * + * Edge case (empty input list): + * OR([]) can either return false (since the disjunction of no values + * is false in some interpretations) or throw an exception. + */ + static class ORGate implements BooleanGate { + @Override + public boolean evaluate(List inputs) { + for (boolean input : inputs) { + if (input) { + return true; + } } + return false; } - return false; } - } - /** - * NOT Gate implementation (Unary operation). - * Only accepts a single input and returns the negation. - */ - static class NOTGate { /** - * Evaluates the negation of a single input. - * - * @param input The input value to be negated. - * @return The negation of the input. + * NOT Gate implementation (Unary operation). + * Only accepts a single input and returns the negation. + * + * Test cases for NOT Gate: + * + * NOT(true) should return false. + * NOT(false) should return true. + * + * Edge case: + * Not applicable, as NOT is a unary operation and requires a single + * input. */ - public boolean evaluate(boolean input) { - return !input; + static class NOTGate { + /** + * Evaluates the negation of a single input. + * + * @param input The input value to be negated. + * @return The negation of the input. + */ + public boolean evaluate(boolean input) { + return !input; + } } - } - /** - * XOR Gate implementation. - * Returns true if an odd number of inputs are true, otherwise false. - */ - static class XORGate implements BooleanGate { - @Override - public boolean evaluate(List inputs) { - boolean result = false; - for (boolean input : inputs) { - result ^= input; + /** + * XOR Gate implementation. + * Returns true if an odd number of inputs are true, otherwise false. + * + * Test cases for XOR Gate: + * + * XOR([true, false]) should return true. + * XOR([true, true]) should return false. + * XOR([false, false]) should return false. + * + * Multiple inputs: + * XOR([true, true, true]) should return true. + * XOR([true, false, true]) should return false (since the XOR of an + * odd number of true inputs is true). + * + * Edge case: + * XOR([]) can either return false (if no inputs are given) or throw an + * exception. + */ + static class XORGate implements BooleanGate { + @Override + public boolean evaluate(List inputs) { + boolean result = false; + for (boolean input : inputs) { + result ^= input; + } + return result; } - return result; } - } - /** - * NAND Gate implementation. - * Returns true if at least one input is false, otherwise false. - */ - static class NANDGate implements BooleanGate { - @Override - public boolean evaluate(List inputs) { - return !new ANDGate().evaluate(inputs); // Equivalent to negation of AND + /** + * NAND Gate implementation. + * Returns true if at least one input is false, otherwise false. + * + * Test cases for NAND Gate: + * + * NAND([true, true]) should return false. + * NAND([true, false]) should return true. + * NAND([false, false]) should return true. + * + * Multiple inputs: + * NAND([true, true, true]) should return false. + * NAND([true, true, false]) should return true. + * + * Edge case: + * NAND([]) can either return true or throw an exception depending on + * your design. + */ + static class NANDGate implements BooleanGate { + @Override + public boolean evaluate(List inputs) { + return !new ANDGate().evaluate(inputs); // Equivalent to negation of AND + } } - } - /** - * NOR Gate implementation. - * Returns true if all inputs are false, otherwise false. - */ - static class NORGate implements BooleanGate { - @Override - public boolean evaluate(List inputs) { - return !new ORGate().evaluate(inputs); // Equivalent to negation of OR + /** + * NOR Gate implementation. + * Returns true if all inputs are false, otherwise false. + * + * Test cases for NOR Gate: + * + * NOR([true, false]) should return false. + * NOR([false, false]) should return true. + * + * Multiple inputs: + * NOR([false, false, false]) should return true. + * NOR([true, true, false]) should return false. + * + * Edge case: + * NOR([]) can either return true or throw an exception. + */ + static class NORGate implements BooleanGate { + @Override + public boolean evaluate(List inputs) { + return !new ORGate().evaluate(inputs); // Equivalent to negation of OR + } } + /** + * Edge Cases and Special Scenarios: + * + * 1. Empty input list: + * - Test handling of empty input lists for multi-input gates. + * - Should throw an exception if the design assumes an empty list is * invalid. + * + * 2. Single input for multi-input gates: + * - AND([true]) -> true + * - OR([false]) -> false + * - XOR([true]) -> true + * - Test behavior with single input as a corner case. + * + * 3. Mixed inputs: + * - AND([true, false, false, true]) -> false + * - Similar tests for OR, XOR, and other gates. + * + * 4. Large input lists: + * - AND([true, true, ..., true]) with 1,000 true values -> true. + * - OR with mostly false and one true -> true. + * + * 5. Randomized tests: + * - Generate random true/false input lists. + * - Validate expected gate outputs, especially for XOR. + * + * 6. Invalid input handling: + * - Test behavior when null is passed as input or within the list. + * - Should either throw an exception or handle per defined behavior. + */ + } -} From c7eacaec4454e162989297ad2b58616201a823e7 Mon Sep 17 00:00:00 2001 From: vansh kabra Date: Fri, 11 Oct 2024 21:51:04 +0530 Subject: [PATCH 03/14] Add algo for BooleanGateslogic and test cases --- .../bitmanipulation/BooleanAlgebraGates.java | 356 ++++++++---------- 1 file changed, 166 insertions(+), 190 deletions(-) diff --git a/src/main/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGates.java b/src/main/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGates.java index 15be881d2b38..4d03a34c8012 100644 --- a/src/main/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGates.java +++ b/src/main/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGates.java @@ -1,214 +1,190 @@ - package com.thealgorithms.bitmanipulation; +package com.thealgorithms.bitmanipulation; - import java.util.List; +import java.util.List; - /** - * Implements various Boolean algebra gates (AND, OR, NOT, XOR, NAND, NOR) - */ - public final class BooleanAlgebraGates { - - private BooleanAlgebraGates() { - // Private constructor to prevent instantiation - } +/** + * Implements various Boolean algebra gates (AND, OR, NOT, XOR, NAND, NOR). + */ +public final class BooleanAlgebraGates { - /** - * Interface representing a Boolean gate that takes multiple inputs and returns a result. - */ - interface BooleanGate { - boolean evaluate(List inputs); - } + private BooleanAlgebraGates() { + // Private constructor to prevent instantiation + } - /** - * AND Gate implementation. - * Returns true if all inputs are true, otherwise false. - * - * Test cases for AND Gate: - * - * AND([true, true]) should return true. - * AND([true, false]) should return false. - * AND([false, false]) should return false. - * - * Multiple inputs: - * AND([true, true, true]) should return true. - * AND([true, false, true]) should return false. - * - * Edge case (empty input list): - * AND([]) can either return true (since the conjunction of no values - * is true in some interpretations) or throw an exception depending - * your design. - */ + /** + * Interface representing a Boolean gate that takes multiple inputs and returns a result. + */ + interface BooleanGate { + boolean evaluate(List inputs); + } - static class ANDGate implements BooleanGate { - @Override - public boolean evaluate(List inputs) { - for (boolean input : inputs) { - if (!input) { - return false; - } + /** + * AND Gate implementation. + * Returns true if all inputs are true; otherwise, false. + * + * Test cases for AND Gate: + * - AND([true, true]) should return true. + * - AND([true, false]) should return false. + * - AND([false, false]) should return false. + * - AND([true, true, true]) should return true. + * - AND([true, false, true]) should return false. + * + * Edge case (empty input list): + * - AND([]) can either return true or throw an exception depending on your design. + */ + static class ANDGate implements BooleanGate { + @Override + public boolean evaluate(List inputs) { + for (boolean input : inputs) { + if (!input) { + return false; } - return true; } + return true; } + } - /** - * OR Gate implementation. - * Returns true if at least one input is true, otherwise false. - * - * Test cases for OR Gate: - * - * OR([true, false]) should return true. - * OR([false, false]) should return false. - * - * Multiple inputs: - * OR([true, true, false]) should return true. - * OR([false, false, false]) should return false. - * - * Edge case (empty input list): - * OR([]) can either return false (since the disjunction of no values - * is false in some interpretations) or throw an exception. - */ - static class ORGate implements BooleanGate { - @Override - public boolean evaluate(List inputs) { - for (boolean input : inputs) { - if (input) { - return true; - } + /** + * OR Gate implementation. + * Returns true if at least one input is true; otherwise, false. + * + * Test cases for OR Gate: + * - OR([true, false]) should return true. + * - OR([false, false]) should return false. + * - OR([true, true, false]) should return true. + * - OR([false, false, false]) should return false. + * + * Edge case (empty input list): + * - OR([]) can either return false or throw an exception. + */ + static class ORGate implements BooleanGate { + @Override + public boolean evaluate(List inputs) { + for (boolean input : inputs) { + if (input) { + return true; } - return false; } + return false; } + } + /** + * NOT Gate implementation (Unary operation). + * Only accepts a single input and returns the negation. + * + * Test cases for NOT Gate: + * - NOT(true) should return false. + * - NOT(false) should return true. + * + * Edge case: + * Not applicable, as NOT is a unary operation and requires a single input. + */ + static class NOTGate { /** - * NOT Gate implementation (Unary operation). - * Only accepts a single input and returns the negation. - * - * Test cases for NOT Gate: - * - * NOT(true) should return false. - * NOT(false) should return true. - * - * Edge case: - * Not applicable, as NOT is a unary operation and requires a single - * input. + * Evaluates the negation of a single input. + * + * @param input The input value to be negated. + * @return The negation of the input. */ - static class NOTGate { - /** - * Evaluates the negation of a single input. - * - * @param input The input value to be negated. - * @return The negation of the input. - */ - public boolean evaluate(boolean input) { - return !input; - } + public boolean evaluate(boolean input) { + return !input; } + } - /** - * XOR Gate implementation. - * Returns true if an odd number of inputs are true, otherwise false. - * - * Test cases for XOR Gate: - * - * XOR([true, false]) should return true. - * XOR([true, true]) should return false. - * XOR([false, false]) should return false. - * - * Multiple inputs: - * XOR([true, true, true]) should return true. - * XOR([true, false, true]) should return false (since the XOR of an - * odd number of true inputs is true). - * - * Edge case: - * XOR([]) can either return false (if no inputs are given) or throw an - * exception. - */ - static class XORGate implements BooleanGate { - @Override - public boolean evaluate(List inputs) { - boolean result = false; - for (boolean input : inputs) { - result ^= input; - } - return result; + /** + * XOR Gate implementation. + * Returns true if an odd number of inputs are true; otherwise, false. + * + * Test cases for XOR Gate: + * - XOR([true, false]) should return true. + * - XOR([true, true]) should return false. + * - XOR([false, false]) should return false. + * - XOR([true, true, true]) should return true. + * - XOR([true, false, true]) should return false. + * + * Edge case: + * - XOR([]) can either return false or throw an exception. + */ + static class XORGate implements BooleanGate { + @Override + public boolean evaluate(List inputs) { + boolean result = false; + for (boolean input : inputs) { + result ^= input; } + return result; } + } - /** - * NAND Gate implementation. - * Returns true if at least one input is false, otherwise false. - * - * Test cases for NAND Gate: - * - * NAND([true, true]) should return false. - * NAND([true, false]) should return true. - * NAND([false, false]) should return true. - * - * Multiple inputs: - * NAND([true, true, true]) should return false. - * NAND([true, true, false]) should return true. - * - * Edge case: - * NAND([]) can either return true or throw an exception depending on - * your design. - */ - static class NANDGate implements BooleanGate { - @Override - public boolean evaluate(List inputs) { - return !new ANDGate().evaluate(inputs); // Equivalent to negation of AND - } + /** + * NAND Gate implementation. + * Returns true if at least one input is false; otherwise, false. + * + * Test cases for NAND Gate: + * - NAND([true, true]) should return false. + * - NAND([true, false]) should return true. + * - NAND([false, false]) should return true. + * - NAND([true, true, true]) should return false. + * - NAND([true, true, false]) should return true. + * + * Edge case: + * - NAND([]) can either return true or throw an exception. + */ + static class NANDGate implements BooleanGate { + @Override + public boolean evaluate(List inputs) { + return !new ANDGate().evaluate(inputs); // Equivalent to negation of AND } + } - /** - * NOR Gate implementation. - * Returns true if all inputs are false, otherwise false. - * - * Test cases for NOR Gate: - * - * NOR([true, false]) should return false. - * NOR([false, false]) should return true. - * - * Multiple inputs: - * NOR([false, false, false]) should return true. - * NOR([true, true, false]) should return false. - * - * Edge case: - * NOR([]) can either return true or throw an exception. - */ - static class NORGate implements BooleanGate { - @Override - public boolean evaluate(List inputs) { - return !new ORGate().evaluate(inputs); // Equivalent to negation of OR - } + /** + * NOR Gate implementation. + * Returns true if all inputs are false; otherwise, false. + * + * Test cases for NOR Gate: + * - NOR([true, false]) should return false. + * - NOR([false, false]) should return true. + * - NOR([false, false, false]) should return true. + * - NOR([true, true, false]) should return false. + * + * Edge case: + * - NOR([]) can either return true or throw an exception. + */ + static class NORGate implements BooleanGate { + @Override + public boolean evaluate(List inputs) { + return !new ORGate().evaluate(inputs); // Equivalent to negation of OR } - /** - * Edge Cases and Special Scenarios: - * - * 1. Empty input list: - * - Test handling of empty input lists for multi-input gates. - * - Should throw an exception if the design assumes an empty list is * invalid. - * - * 2. Single input for multi-input gates: - * - AND([true]) -> true - * - OR([false]) -> false - * - XOR([true]) -> true - * - Test behavior with single input as a corner case. - * - * 3. Mixed inputs: - * - AND([true, false, false, true]) -> false - * - Similar tests for OR, XOR, and other gates. - * - * 4. Large input lists: - * - AND([true, true, ..., true]) with 1,000 true values -> true. - * - OR with mostly false and one true -> true. - * - * 5. Randomized tests: - * - Generate random true/false input lists. - * - Validate expected gate outputs, especially for XOR. - * - * 6. Invalid input handling: - * - Test behavior when null is passed as input or within the list. - * - Should either throw an exception or handle per defined behavior. - */ - } + + /** + * Edge Cases and Special Scenarios: + * + * 1. Empty input list: + * - Test handling of empty input lists for multi-input gates. + * - Should throw an exception if the design assumes an empty list is invalid. + * + * 2. Single input for multi-input gates: + * - AND([true]) -> true + * - OR([false]) -> false + * - XOR([true]) -> true + * - Test behavior with single input as a corner case. + * + * 3. Mixed inputs: + * - AND([true, false, false, true]) -> false + * - Similar tests for OR, XOR, and other gates. + * + * 4. Large input lists: + * - AND([true, true, ..., true]) with 1,000 true values -> true. + * - OR with mostly false and one true -> true. + * + * 5. Randomized tests: + * - Generate random true/false input lists. + * - Validate expected gate outputs, especially for XOR. + * + * 6. Invalid input handling: + * - Test behavior when null is passed as input or within the list. + * - Should either throw an exception or handle per defined behavior. + */ +} From aa2daea1107fdae8690234289f9c9adf88219a0c Mon Sep 17 00:00:00 2001 From: vansh kabra Date: Fri, 11 Oct 2024 21:58:04 +0530 Subject: [PATCH 04/14] Add algo for BooleanGateslogic and test cases --- .../bitmanipulation/BooleanAlgebraGates.java | 195 +++++++++++------- 1 file changed, 119 insertions(+), 76 deletions(-) diff --git a/src/main/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGates.java b/src/main/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGates.java index 4d03a34c8012..e032f85f4260 100644 --- a/src/main/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGates.java +++ b/src/main/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGates.java @@ -4,33 +4,44 @@ /** * Implements various Boolean algebra gates (AND, OR, NOT, XOR, NAND, NOR). + * This class provides the logic for fundamental Boolean operations that can be + * used in various computational contexts. */ public final class BooleanAlgebraGates { - private BooleanAlgebraGates() { - // Private constructor to prevent instantiation - } + // Private constructor to prevent instantiation + private BooleanAlgebraGates() {} /** * Interface representing a Boolean gate that takes multiple inputs and returns a result. */ interface BooleanGate { + /** + * Evaluates the Boolean gate with the provided inputs. + * + * @param inputs a list of Boolean values representing the gate inputs. + * @return the result of the Boolean operation. + */ boolean evaluate(List inputs); } /** * AND Gate implementation. - * Returns true if all inputs are true; otherwise, false. + * Returns true if all inputs are true; otherwise, returns false. * - * Test cases for AND Gate: - * - AND([true, true]) should return true. - * - AND([true, false]) should return false. - * - AND([false, false]) should return false. - * - AND([true, true, true]) should return true. - * - AND([true, false, true]) should return false. - * - * Edge case (empty input list): - * - AND([]) can either return true or throw an exception depending on your design. + *

Test cases for AND Gate:

+ *
    + *
  • AND([true, true]) should return true.
  • + *
  • AND([true, false]) should return false.
  • + *
  • AND([false, false]) should return false.
  • + *
  • AND([true, true, true]) should return true.
  • + *
  • AND([true, false, true]) should return false.
  • + *
+ * + *

Edge case (empty input list):

+ *
    + *
  • AND([]) can either return true or throw an exception depending on your design.
  • + *
*/ static class ANDGate implements BooleanGate { @Override @@ -46,16 +57,20 @@ public boolean evaluate(List inputs) { /** * OR Gate implementation. - * Returns true if at least one input is true; otherwise, false. + * Returns true if at least one input is true; otherwise, returns false. * - * Test cases for OR Gate: - * - OR([true, false]) should return true. - * - OR([false, false]) should return false. - * - OR([true, true, false]) should return true. - * - OR([false, false, false]) should return false. - * - * Edge case (empty input list): - * - OR([]) can either return false or throw an exception. + *

Test cases for OR Gate:

+ *
    + *
  • OR([true, false]) should return true.
  • + *
  • OR([false, false]) should return false.
  • + *
  • OR([true, true, false]) should return true.
  • + *
  • OR([false, false, false]) should return false.
  • + *
+ * + *

Edge case (empty input list):

+ *
    + *
  • OR([]) can either return false or throw an exception.
  • + *
*/ static class ORGate implements BooleanGate { @Override @@ -73,12 +88,16 @@ public boolean evaluate(List inputs) { * NOT Gate implementation (Unary operation). * Only accepts a single input and returns the negation. * - * Test cases for NOT Gate: - * - NOT(true) should return false. - * - NOT(false) should return true. + *

Test cases for NOT Gate:

+ *
    + *
  • NOT(true) should return false.
  • + *
  • NOT(false) should return true.
  • + *
* - * Edge case: - * Not applicable, as NOT is a unary operation and requires a single input. + *

Edge case:

+ *
    + *
  • Not applicable, as NOT is a unary operation and requires a single input.
  • + *
*/ static class NOTGate { /** @@ -94,17 +113,21 @@ public boolean evaluate(boolean input) { /** * XOR Gate implementation. - * Returns true if an odd number of inputs are true; otherwise, false. + * Returns true if an odd number of inputs are true; otherwise, returns false. * - * Test cases for XOR Gate: - * - XOR([true, false]) should return true. - * - XOR([true, true]) should return false. - * - XOR([false, false]) should return false. - * - XOR([true, true, true]) should return true. - * - XOR([true, false, true]) should return false. - * - * Edge case: - * - XOR([]) can either return false or throw an exception. + *

Test cases for XOR Gate:

+ *
    + *
  • XOR([true, false]) should return true.
  • + *
  • XOR([true, true]) should return false.
  • + *
  • XOR([false, false]) should return false.
  • + *
  • XOR([true, true, true]) should return true.
  • + *
  • XOR([true, false, true]) should return false.
  • + *
+ * + *

Edge case:

+ *
    + *
  • XOR([]) can either return false or throw an exception.
  • + *
*/ static class XORGate implements BooleanGate { @Override @@ -119,17 +142,21 @@ public boolean evaluate(List inputs) { /** * NAND Gate implementation. - * Returns true if at least one input is false; otherwise, false. + * Returns true if at least one input is false; otherwise, returns false. * - * Test cases for NAND Gate: - * - NAND([true, true]) should return false. - * - NAND([true, false]) should return true. - * - NAND([false, false]) should return true. - * - NAND([true, true, true]) should return false. - * - NAND([true, true, false]) should return true. - * - * Edge case: - * - NAND([]) can either return true or throw an exception. + *

Test cases for NAND Gate:

+ *
    + *
  • NAND([true, true]) should return false.
  • + *
  • NAND([true, false]) should return true.
  • + *
  • NAND([false, false]) should return true.
  • + *
  • NAND([true, true, true]) should return false.
  • + *
  • NAND([true, true, false]) should return true.
  • + *
+ * + *

Edge case:

+ *
    + *
  • NAND([]) can either return true or throw an exception.
  • + *
*/ static class NANDGate implements BooleanGate { @Override @@ -140,16 +167,20 @@ public boolean evaluate(List inputs) { /** * NOR Gate implementation. - * Returns true if all inputs are false; otherwise, false. + * Returns true if all inputs are false; otherwise, returns false. * - * Test cases for NOR Gate: - * - NOR([true, false]) should return false. - * - NOR([false, false]) should return true. - * - NOR([false, false, false]) should return true. - * - NOR([true, true, false]) should return false. - * - * Edge case: - * - NOR([]) can either return true or throw an exception. + *

Test cases for NOR Gate:

+ *
    + *
  • NOR([true, false]) should return false.
  • + *
  • NOR([false, false]) should return true.
  • + *
  • NOR([false, false, false]) should return true.
  • + *
  • NOR([true, true, false]) should return false.
  • + *
+ * + *

Edge case:

+ *
    + *
  • NOR([]) can either return true or throw an exception.
  • + *
*/ static class NORGate implements BooleanGate { @Override @@ -161,30 +192,42 @@ public boolean evaluate(List inputs) { /** * Edge Cases and Special Scenarios: * - * 1. Empty input list: - * - Test handling of empty input lists for multi-input gates. - * - Should throw an exception if the design assumes an empty list is invalid. + *

1. Empty input list:

+ *
    + *
  • Test handling of empty input lists for multi-input gates.
  • + *
  • Should throw an exception if the design assumes an empty list is invalid.
  • + *
* - * 2. Single input for multi-input gates: - * - AND([true]) -> true - * - OR([false]) -> false - * - XOR([true]) -> true - * - Test behavior with single input as a corner case. + *

2. Single input for multi-input gates:

+ *
    + *
  • AND([true]) -> true
  • + *
  • OR([false]) -> false
  • + *
  • XOR([true]) -> true
  • + *
  • Test behavior with single input as a corner case.
  • + *
* - * 3. Mixed inputs: - * - AND([true, false, false, true]) -> false - * - Similar tests for OR, XOR, and other gates. + *

3. Mixed inputs:

+ *
    + *
  • AND([true, false, false, true]) -> false
  • + *
  • Similar tests for OR, XOR, and other gates.
  • + *
* - * 4. Large input lists: - * - AND([true, true, ..., true]) with 1,000 true values -> true. - * - OR with mostly false and one true -> true. + *

4. Large input lists:

+ *
    + *
  • AND([true, true, ..., true]) with 1,000 true values -> true.
  • + *
  • OR with mostly false and one true -> true.
  • + *
* - * 5. Randomized tests: - * - Generate random true/false input lists. - * - Validate expected gate outputs, especially for XOR. + *

5. Randomized tests:

+ *
    + *
  • Generate random true/false input lists.
  • + *
  • Validate expected gate outputs, especially for XOR.
  • + *
* - * 6. Invalid input handling: - * - Test behavior when null is passed as input or within the list. - * - Should either throw an exception or handle per defined behavior. + *

6. Invalid input handling:

+ *
    + *
  • Test behavior when null is passed as input or within the list.
  • + *
  • Should either throw an exception or handle per defined behavior.
  • + *
*/ } From a250a95a8671d5a93b27895ffa1eb3cdf1657bf4 Mon Sep 17 00:00:00 2001 From: vansh kabra Date: Sat, 12 Oct 2024 09:56:05 +0530 Subject: [PATCH 05/14] Add algo for BooleanGateslogic and test cases --- .../bitmanipulation/BooleanAlgebraGates.java | 154 ++---------------- .../BooleanAlgebraGatesTest.java | 113 +++++++++++++ 2 files changed, 129 insertions(+), 138 deletions(-) create mode 100644 src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java diff --git a/src/main/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGates.java b/src/main/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGates.java index e032f85f4260..869466320831 100644 --- a/src/main/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGates.java +++ b/src/main/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGates.java @@ -3,45 +3,30 @@ import java.util.List; /** - * Implements various Boolean algebra gates (AND, OR, NOT, XOR, NAND, NOR). - * This class provides the logic for fundamental Boolean operations that can be - * used in various computational contexts. + * Implements various Boolean algebra gates (AND, OR, NOT, XOR, NAND, NOR) */ public final class BooleanAlgebraGates { - // Private constructor to prevent instantiation - private BooleanAlgebraGates() {} + private BooleanAlgebraGates() { + // Prevent instantiation + } /** - * Interface representing a Boolean gate that takes multiple inputs and returns a result. + * Represents a Boolean gate that takes multiple inputs and returns a result. */ interface BooleanGate { /** - * Evaluates the Boolean gate with the provided inputs. + * Evaluates the gate with the given inputs. * - * @param inputs a list of Boolean values representing the gate inputs. - * @return the result of the Boolean operation. + * @param inputs The input values for the gate. + * @return The result of the evaluation. */ boolean evaluate(List inputs); } /** * AND Gate implementation. - * Returns true if all inputs are true; otherwise, returns false. - * - *

Test cases for AND Gate:

- *
    - *
  • AND([true, true]) should return true.
  • - *
  • AND([true, false]) should return false.
  • - *
  • AND([false, false]) should return false.
  • - *
  • AND([true, true, true]) should return true.
  • - *
  • AND([true, false, true]) should return false.
  • - *
- * - *

Edge case (empty input list):

- *
    - *
  • AND([]) can either return true or throw an exception depending on your design.
  • - *
+ * Returns true if all inputs are true; otherwise, false. */ static class ANDGate implements BooleanGate { @Override @@ -57,20 +42,7 @@ public boolean evaluate(List inputs) { /** * OR Gate implementation. - * Returns true if at least one input is true; otherwise, returns false. - * - *

Test cases for OR Gate:

- *
    - *
  • OR([true, false]) should return true.
  • - *
  • OR([false, false]) should return false.
  • - *
  • OR([true, true, false]) should return true.
  • - *
  • OR([false, false, false]) should return false.
  • - *
- * - *

Edge case (empty input list):

- *
    - *
  • OR([]) can either return false or throw an exception.
  • - *
+ * Returns true if at least one input is true; otherwise, false. */ static class ORGate implements BooleanGate { @Override @@ -86,25 +58,14 @@ public boolean evaluate(List inputs) { /** * NOT Gate implementation (Unary operation). - * Only accepts a single input and returns the negation. - * - *

Test cases for NOT Gate:

- *
    - *
  • NOT(true) should return false.
  • - *
  • NOT(false) should return true.
  • - *
- * - *

Edge case:

- *
    - *
  • Not applicable, as NOT is a unary operation and requires a single input.
  • - *
+ * Negates a single input value. */ static class NOTGate { /** - * Evaluates the negation of a single input. + * Evaluates the negation of the input. * * @param input The input value to be negated. - * @return The negation of the input. + * @return The negated value. */ public boolean evaluate(boolean input) { return !input; @@ -113,21 +74,7 @@ public boolean evaluate(boolean input) { /** * XOR Gate implementation. - * Returns true if an odd number of inputs are true; otherwise, returns false. - * - *

Test cases for XOR Gate:

- *
    - *
  • XOR([true, false]) should return true.
  • - *
  • XOR([true, true]) should return false.
  • - *
  • XOR([false, false]) should return false.
  • - *
  • XOR([true, true, true]) should return true.
  • - *
  • XOR([true, false, true]) should return false.
  • - *
- * - *

Edge case:

- *
    - *
  • XOR([]) can either return false or throw an exception.
  • - *
+ * Returns true if an odd number of inputs are true; otherwise, false. */ static class XORGate implements BooleanGate { @Override @@ -142,21 +89,7 @@ public boolean evaluate(List inputs) { /** * NAND Gate implementation. - * Returns true if at least one input is false; otherwise, returns false. - * - *

Test cases for NAND Gate:

- *
    - *
  • NAND([true, true]) should return false.
  • - *
  • NAND([true, false]) should return true.
  • - *
  • NAND([false, false]) should return true.
  • - *
  • NAND([true, true, true]) should return false.
  • - *
  • NAND([true, true, false]) should return true.
  • - *
- * - *

Edge case:

- *
    - *
  • NAND([]) can either return true or throw an exception.
  • - *
+ * Returns true if at least one input is false; otherwise, false. */ static class NANDGate implements BooleanGate { @Override @@ -167,20 +100,7 @@ public boolean evaluate(List inputs) { /** * NOR Gate implementation. - * Returns true if all inputs are false; otherwise, returns false. - * - *

Test cases for NOR Gate:

- *
    - *
  • NOR([true, false]) should return false.
  • - *
  • NOR([false, false]) should return true.
  • - *
  • NOR([false, false, false]) should return true.
  • - *
  • NOR([true, true, false]) should return false.
  • - *
- * - *

Edge case:

- *
    - *
  • NOR([]) can either return true or throw an exception.
  • - *
+ * Returns true if all inputs are false; otherwise, false. */ static class NORGate implements BooleanGate { @Override @@ -188,46 +108,4 @@ public boolean evaluate(List inputs) { return !new ORGate().evaluate(inputs); // Equivalent to negation of OR } } - - /** - * Edge Cases and Special Scenarios: - * - *

1. Empty input list:

- *
    - *
  • Test handling of empty input lists for multi-input gates.
  • - *
  • Should throw an exception if the design assumes an empty list is invalid.
  • - *
- * - *

2. Single input for multi-input gates:

- *
    - *
  • AND([true]) -> true
  • - *
  • OR([false]) -> false
  • - *
  • XOR([true]) -> true
  • - *
  • Test behavior with single input as a corner case.
  • - *
- * - *

3. Mixed inputs:

- *
    - *
  • AND([true, false, false, true]) -> false
  • - *
  • Similar tests for OR, XOR, and other gates.
  • - *
- * - *

4. Large input lists:

- *
    - *
  • AND([true, true, ..., true]) with 1,000 true values -> true.
  • - *
  • OR with mostly false and one true -> true.
  • - *
- * - *

5. Randomized tests:

- *
    - *
  • Generate random true/false input lists.
  • - *
  • Validate expected gate outputs, especially for XOR.
  • - *
- * - *

6. Invalid input handling:

- *
    - *
  • Test behavior when null is passed as input or within the list.
  • - *
  • Should either throw an exception or handle per defined behavior.
  • - *
- */ } diff --git a/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java b/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java new file mode 100644 index 000000000000..69a88a27905f --- /dev/null +++ b/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java @@ -0,0 +1,113 @@ +package com.thealgorithms.bitmanipulation; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Stream; +import com.thealgorithms.bitmanipulation.BooleanAlgebraGates.ANDGate; +import com.thealgorithms.bitmanipulation.BooleanAlgebraGates.BooleanGate; +import com.thealgorithms.bitmanipulation.BooleanAlgebraGates.NANDGate; +import com.thealgorithms.bitmanipulation.BooleanAlgebraGates.NORGate; +import com.thealgorithms.bitmanipulation.BooleanAlgebraGates.NOTGate; +import com.thealgorithms.bitmanipulation.BooleanAlgebraGates.ORGate; +import com.thealgorithms.bitmanipulation.BooleanAlgebraGates.XORGate; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.MethodSource; + +class BooleanAlgebraGatesTest { + + @ParameterizedTest(name = "ANDGate Test Case {index}: inputs={0} -> expected={1}") + @MethodSource("provideAndGateTestCases") + void testANDGate(List inputs, boolean expected) { + BooleanGate gate = new ANDGate(); + assertEquals(expected, gate.evaluate(inputs)); + } + + @ParameterizedTest(name = "ORGate Test Case {index}: inputs={0} -> expected={1}") + @MethodSource("provideOrGateTestCases") + void testORGate(List inputs, boolean expected) { + BooleanGate gate = new ORGate(); + assertEquals(expected, gate.evaluate(inputs)); + } + + @ParameterizedTest(name = "NOTGate Test Case {index}: input={0} -> expected={1}") + @CsvSource({ + "true, false", + "false, true" + }) + void testNOTGate(boolean input, boolean expected) { + NOTGate gate = new NOTGate(); + assertEquals(expected, gate.evaluate(input)); + } + + @ParameterizedTest(name = "XORGate Test Case {index}: inputs={0} -> expected={1}") + @MethodSource("provideXorGateTestCases") + void testXORGate(List inputs, boolean expected) { + BooleanGate gate = new XORGate(); + assertEquals(expected, gate.evaluate(inputs)); + } + + @ParameterizedTest(name = "NANDGate Test Case {index}: inputs={0} -> expected={1}") + @MethodSource("provideNandGateTestCases") + void testNANDGate(List inputs, boolean expected) { + BooleanGate gate = new NANDGate(); + assertEquals(expected, gate.evaluate(inputs)); + } + + @ParameterizedTest(name = "NORGate Test Case {index}: inputs={0} -> expected={1}") + @MethodSource("provideNorGateTestCases") + void testNORGate(List inputs, boolean expected) { + BooleanGate gate = new NORGate(); + assertEquals(expected, gate.evaluate(inputs)); + } + + // Helper methods to provide test data for each gate + + static Stream provideAndGateTestCases() { + return Stream.of( + new Object[]{Arrays.asList(true, true, true), true}, + new Object[]{Arrays.asList(true, false, true), false}, + new Object[]{Arrays.asList(false, false, false), false}, + new Object[]{Collections.emptyList(), true} // AND over no inputs is true + ); + } + + static Stream provideOrGateTestCases() { + return Stream.of( + new Object[]{Arrays.asList(true, false, false), true}, + new Object[]{Arrays.asList(false, false, false), false}, + new Object[]{Arrays.asList(true, true, true), true}, + new Object[]{Collections.emptyList(), false} // OR over no inputs is false + ); + } + + static Stream provideXorGateTestCases() { + return Stream.of( + new Object[]{Arrays.asList(true, false, true), false}, // XOR over odd true + new Object[]{Arrays.asList(true, false, false), true}, // XOR over single true + new Object[]{Arrays.asList(false, false, false), false},// XOR over all false + new Object[]{Arrays.asList(true, true), false} // XOR over even true + ); + } + + static Stream provideNandGateTestCases() { + return Stream.of( + new Object[]{Arrays.asList(true, true, true), false}, // NAND of all true is false + new Object[]{Arrays.asList(true, false), true}, // NAND with one false is true + new Object[]{Arrays.asList(false, false), true}, // NAND of all false is true + new Object[]{Collections.emptyList(), false} // NAND over no inputs is false (negation of AND) + ); + } + + static Stream provideNorGateTestCases() { + return Stream.of( + new Object[]{Arrays.asList(false, false), true}, // NOR of all false is true + new Object[]{Arrays.asList(false, true), false}, // NOR with one true is false + new Object[]{Arrays.asList(true, true), false}, // NOR of all true is false + new Object[]{Collections.emptyList(), true} // NOR over no inputs is true (negation of OR) + ); + } +} \ No newline at end of file From 5023e8a865ebe3fc77a6f6b8f795f5e5f8c38f22 Mon Sep 17 00:00:00 2001 From: vansh kabra Date: Sat, 12 Oct 2024 10:08:07 +0530 Subject: [PATCH 06/14] Add algo for BooleanGateslogic and test cases --- .../bitmanipulation/BooleanAlgebraGatesTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java b/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java index 69a88a27905f..878fb8ab6b59 100644 --- a/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java +++ b/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java @@ -1,3 +1,4 @@ + package com.thealgorithms.bitmanipulation; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -34,10 +35,7 @@ void testORGate(List inputs, boolean expected) { } @ParameterizedTest(name = "NOTGate Test Case {index}: input={0} -> expected={1}") - @CsvSource({ - "true, false", - "false, true" - }) + @CsvSource({"true, false", "false, true"}) void testNOTGate(boolean input, boolean expected) { NOTGate gate = new NOTGate(); assertEquals(expected, gate.evaluate(input)); From e0dc8f534651899d2c38c219e32c8f176ded9188 Mon Sep 17 00:00:00 2001 From: vansh kabra Date: Sat, 12 Oct 2024 10:12:25 +0530 Subject: [PATCH 07/14] Add algo for BooleanGateslogic and test cases --- .../bitmanipulation/BooleanAlgebraGatesTest.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java b/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java index 878fb8ab6b59..6bd117cc5789 100644 --- a/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java +++ b/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java @@ -1,4 +1,3 @@ - package com.thealgorithms.bitmanipulation; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -35,7 +34,10 @@ void testORGate(List inputs, boolean expected) { } @ParameterizedTest(name = "NOTGate Test Case {index}: input={0} -> expected={1}") - @CsvSource({"true, false", "false, true"}) + @CsvSource({ + "true, false", + "false, true" + }) void testNOTGate(boolean input, boolean expected) { NOTGate gate = new NOTGate(); assertEquals(expected, gate.evaluate(input)); @@ -108,4 +110,4 @@ static Stream provideNorGateTestCases() { new Object[]{Collections.emptyList(), true} // NOR over no inputs is true (negation of OR) ); } -} \ No newline at end of file +} From a70868a60529135db00dd1496c610188a66de3fe Mon Sep 17 00:00:00 2001 From: vansh kabra Date: Sat, 12 Oct 2024 10:19:55 +0530 Subject: [PATCH 08/14] Add algo for BooleanGateslogic and test cases --- .../BooleanAlgebraGatesTest.java | 53 +++++++++---------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java b/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java index 6bd117cc5789..cd9c1091343b 100644 --- a/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java +++ b/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java @@ -2,10 +2,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.stream.Stream; import com.thealgorithms.bitmanipulation.BooleanAlgebraGates.ANDGate; import com.thealgorithms.bitmanipulation.BooleanAlgebraGates.BooleanGate; import com.thealgorithms.bitmanipulation.BooleanAlgebraGates.NANDGate; @@ -13,6 +9,10 @@ import com.thealgorithms.bitmanipulation.BooleanAlgebraGates.NOTGate; import com.thealgorithms.bitmanipulation.BooleanAlgebraGates.ORGate; import com.thealgorithms.bitmanipulation.BooleanAlgebraGates.XORGate; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.MethodSource; @@ -34,10 +34,7 @@ void testORGate(List inputs, boolean expected) { } @ParameterizedTest(name = "NOTGate Test Case {index}: input={0} -> expected={1}") - @CsvSource({ - "true, false", - "false, true" - }) + @CsvSource({"true, false", "false, true"}) void testNOTGate(boolean input, boolean expected) { NOTGate gate = new NOTGate(); assertEquals(expected, gate.evaluate(input)); @@ -68,46 +65,46 @@ void testNORGate(List inputs, boolean expected) { static Stream provideAndGateTestCases() { return Stream.of( - new Object[]{Arrays.asList(true, true, true), true}, - new Object[]{Arrays.asList(true, false, true), false}, - new Object[]{Arrays.asList(false, false, false), false}, - new Object[]{Collections.emptyList(), true} // AND over no inputs is true + new Object[]{Arrays.asList(true, true, true), true}, + new Object[]{Arrays.asList(true, false, true), false}, + new Object[]{Arrays.asList(false, false, false), false}, + new Object[]{Collections.emptyList(), true} // AND over no inputs is true ); } static Stream provideOrGateTestCases() { return Stream.of( - new Object[]{Arrays.asList(true, false, false), true}, - new Object[]{Arrays.asList(false, false, false), false}, - new Object[]{Arrays.asList(true, true, true), true}, - new Object[]{Collections.emptyList(), false} // OR over no inputs is false + new Object[]{Arrays.asList(true, false, false), true}, + new Object[]{Arrays.asList(false, false, false), false}, + new Object[]{Arrays.asList(true, true, true), true}, + new Object[]{Collections.emptyList(), false} // OR over no inputs is false ); } static Stream provideXorGateTestCases() { return Stream.of( - new Object[]{Arrays.asList(true, false, true), false}, // XOR over odd true - new Object[]{Arrays.asList(true, false, false), true}, // XOR over single true - new Object[]{Arrays.asList(false, false, false), false},// XOR over all false - new Object[]{Arrays.asList(true, true), false} // XOR over even true + new Object[]{Arrays.asList(true, false, true), false}, // XOR over odd true + new Object[]{Arrays.asList(true, false, false), true}, // XOR over single true + new Object[]{Arrays.asList(false, false, false), false},// XOR over all false + new Object[]{Arrays.asList(true, true), false} // XOR over even true ); } static Stream provideNandGateTestCases() { return Stream.of( - new Object[]{Arrays.asList(true, true, true), false}, // NAND of all true is false - new Object[]{Arrays.asList(true, false), true}, // NAND with one false is true - new Object[]{Arrays.asList(false, false), true}, // NAND of all false is true - new Object[]{Collections.emptyList(), false} // NAND over no inputs is false (negation of AND) + new Object[]{Arrays.asList(true, true, true), false}, // NAND of all true is false + new Object[]{Arrays.asList(true, false), true}, // NAND with one false is true + new Object[]{Arrays.asList(false, false), true}, // NAND of all false is true + new Object[]{Collections.emptyList(), false} // NAND over no inputs is false (negation of AND) ); } static Stream provideNorGateTestCases() { return Stream.of( - new Object[]{Arrays.asList(false, false), true}, // NOR of all false is true - new Object[]{Arrays.asList(false, true), false}, // NOR with one true is false - new Object[]{Arrays.asList(true, true), false}, // NOR of all true is false - new Object[]{Collections.emptyList(), true} // NOR over no inputs is true (negation of OR) + new Object[]{Arrays.asList(false, false), true}, // NOR of all false is true + new Object[]{Arrays.asList(false, true), false}, // NOR with one true is false + new Object[]{Arrays.asList(true, true), false}, // NOR of all true is false + new Object[]{Collections.emptyList(), true} // NOR over no inputs is true (negation of OR) ); } } From 880976b0e8354313c33986a7dbc98867afbc31ff Mon Sep 17 00:00:00 2001 From: vansh kabra Date: Sat, 12 Oct 2024 10:26:19 +0530 Subject: [PATCH 09/14] Add algo for BooleanGateslogic and test cases --- .../BooleanAlgebraGatesTest.java | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java b/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java index cd9c1091343b..24a23392fb62 100644 --- a/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java +++ b/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java @@ -64,26 +64,22 @@ void testNORGate(List inputs, boolean expected) { // Helper methods to provide test data for each gate static Stream provideAndGateTestCases() { - return Stream.of( - new Object[]{Arrays.asList(true, true, true), true}, - new Object[]{Arrays.asList(true, false, true), false}, - new Object[]{Arrays.asList(false, false, false), false}, - new Object[]{Collections.emptyList(), true} // AND over no inputs is true + return Stream.of(new Object[]{Arrays.asList(true, true, true), true},new Object[]{Arrays.asList(true, false, true), false}, + new Object[]{Arrays.asList(false, false, false), false}, + new Object[]{Collections.emptyList(), true} // AND over no inputs is true ); } static Stream provideOrGateTestCases() { - return Stream.of( - new Object[]{Arrays.asList(true, false, false), true}, - new Object[]{Arrays.asList(false, false, false), false}, - new Object[]{Arrays.asList(true, true, true), true}, - new Object[]{Collections.emptyList(), false} // OR over no inputs is false + return Stream.of(new Object[]{Arrays.asList(true, false, false), true}, + new Object[]{Arrays.asList(false, false, false), false}, + new Object[]{Arrays.asList(true, true, true), true}, + new Object[]{Collections.emptyList(), false} // OR over no inputs is false ); } static Stream provideXorGateTestCases() { - return Stream.of( - new Object[]{Arrays.asList(true, false, true), false}, // XOR over odd true + return Stream.of(new Object[]{Arrays.asList(true, false, true), false}, // XOR over odd true new Object[]{Arrays.asList(true, false, false), true}, // XOR over single true new Object[]{Arrays.asList(false, false, false), false},// XOR over all false new Object[]{Arrays.asList(true, true), false} // XOR over even true @@ -91,8 +87,7 @@ static Stream provideXorGateTestCases() { } static Stream provideNandGateTestCases() { - return Stream.of( - new Object[]{Arrays.asList(true, true, true), false}, // NAND of all true is false + return Stream.of(new Object[]{Arrays.asList(true, true, true), false}, // NAND of all true is false new Object[]{Arrays.asList(true, false), true}, // NAND with one false is true new Object[]{Arrays.asList(false, false), true}, // NAND of all false is true new Object[]{Collections.emptyList(), false} // NAND over no inputs is false (negation of AND) @@ -100,8 +95,7 @@ static Stream provideNandGateTestCases() { } static Stream provideNorGateTestCases() { - return Stream.of( - new Object[]{Arrays.asList(false, false), true}, // NOR of all false is true + return Stream.of(new Object[]{Arrays.asList(false, false),true}, // NOR of all false is true new Object[]{Arrays.asList(false, true), false}, // NOR with one true is false new Object[]{Arrays.asList(true, true), false}, // NOR of all true is false new Object[]{Collections.emptyList(), true} // NOR over no inputs is true (negation of OR) From 7f0733bc3facfa7643dd1260b11fd5f7c43422e4 Mon Sep 17 00:00:00 2001 From: vansh kabra Date: Sat, 12 Oct 2024 10:31:50 +0530 Subject: [PATCH 10/14] Add algo for BooleanGateslogic and test cases --- .../BooleanAlgebraGatesTest.java | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java b/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java index 24a23392fb62..5911644f37f7 100644 --- a/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java +++ b/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java @@ -64,41 +64,36 @@ void testNORGate(List inputs, boolean expected) { // Helper methods to provide test data for each gate static Stream provideAndGateTestCases() { - return Stream.of(new Object[]{Arrays.asList(true, true, true), true},new Object[]{Arrays.asList(true, false, true), false}, - new Object[]{Arrays.asList(false, false, false), false}, - new Object[]{Collections.emptyList(), true} // AND over no inputs is true + return Stream.of(new Object[]{Arrays.asList(true, true, true), true}, new Object[]{Arrays.asList(true, false, true), false}, new Object[]{Arrays.asList(false, false, false), false}, new Object[]{Collections.emptyList(), true} // AND over no inputs is true ); } static Stream provideOrGateTestCases() { - return Stream.of(new Object[]{Arrays.asList(true, false, false), true}, - new Object[]{Arrays.asList(false, false, false), false}, - new Object[]{Arrays.asList(true, true, true), true}, - new Object[]{Collections.emptyList(), false} // OR over no inputs is false + return Stream.of(new Object[]{Arrays.asList(true, false, false), true}, new Object[]{Arrays.asList(false, false, false), false}, new Object[]{Arrays.asList(true, true, true), true}, new Object[]{Collections.emptyList(), false} // OR over no inputs is false ); } static Stream provideXorGateTestCases() { return Stream.of(new Object[]{Arrays.asList(true, false, true), false}, // XOR over odd true - new Object[]{Arrays.asList(true, false, false), true}, // XOR over single true - new Object[]{Arrays.asList(false, false, false), false},// XOR over all false - new Object[]{Arrays.asList(true, true), false} // XOR over even true + new Object[]{Arrays.asList(true, false, false), true}, // XOR over single true + new Object[]{Arrays.asList(false, false, false), false}, // XOR over all false + new Object[]{Arrays.asList(true, true), false} // XOR over even true ); } static Stream provideNandGateTestCases() { - return Stream.of(new Object[]{Arrays.asList(true, true, true), false}, // NAND of all true is false - new Object[]{Arrays.asList(true, false), true}, // NAND with one false is true - new Object[]{Arrays.asList(false, false), true}, // NAND of all false is true - new Object[]{Collections.emptyList(), false} // NAND over no inputs is false (negation of AND) + return Stream.of(new Object[]{Arrays.asList(true, true, true), false}, // NAND of all true is false + new Object[]{Arrays.asList(true, false), true}, // NAND with one false is true + new Object[]{Arrays.asList(false, false), true}, // NAND of all false is true + new Object[]{Collections.emptyList(), false} // NAND over no inputs is false (negation of AND) ); } static Stream provideNorGateTestCases() { - return Stream.of(new Object[]{Arrays.asList(false, false),true}, // NOR of all false is true - new Object[]{Arrays.asList(false, true), false}, // NOR with one true is false - new Object[]{Arrays.asList(true, true), false}, // NOR of all true is false - new Object[]{Collections.emptyList(), true} // NOR over no inputs is true (negation of OR) + return Stream.of(new Object[]{Arrays.asList(false, false),true}, // NOR of all false is true + new Object[]{Arrays.asList(false, true), false}, // NOR with one true is false + new Object[]{Arrays.asList(true, true), false}, // NOR of all true is false + new Object[]{Collections.emptyList(), true} // NOR over no inputs is true (negation of OR) ); } } From e32089a54383c19b61175302bbec55be39c96950 Mon Sep 17 00:00:00 2001 From: vansh kabra Date: Sat, 12 Oct 2024 10:35:27 +0530 Subject: [PATCH 11/14] Add algo for BooleanGateslogic and test cases and spaces --- .../bitmanipulation/BooleanAlgebraGatesTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java b/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java index 5911644f37f7..b8a2afc28315 100644 --- a/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java +++ b/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java @@ -64,17 +64,17 @@ void testNORGate(List inputs, boolean expected) { // Helper methods to provide test data for each gate static Stream provideAndGateTestCases() { - return Stream.of(new Object[]{Arrays.asList(true, true, true), true}, new Object[]{Arrays.asList(true, false, true), false}, new Object[]{Arrays.asList(false, false, false), false}, new Object[]{Collections.emptyList(), true} // AND over no inputs is true + return Stream.of(new Object[] {Arrays.asList(true, true, true), true}, new Object[]{Arrays.asList(true, false, true), false}, new Object[]{Arrays.asList(false, false, false), false}, new Object[]{Collections.emptyList(), true} // AND over no inputs is true ); } static Stream provideOrGateTestCases() { - return Stream.of(new Object[]{Arrays.asList(true, false, false), true}, new Object[]{Arrays.asList(false, false, false), false}, new Object[]{Arrays.asList(true, true, true), true}, new Object[]{Collections.emptyList(), false} // OR over no inputs is false + return Stream.of(new Object[] {Arrays.asList(true, false, false), true}, new Object[]{Arrays.asList(false, false, false), false}, new Object[]{Arrays.asList(true, true, true), true}, new Object[]{Collections.emptyList(), false} // OR over no inputs is false ); } static Stream provideXorGateTestCases() { - return Stream.of(new Object[]{Arrays.asList(true, false, true), false}, // XOR over odd true + return Stream.of(new Object[] {Arrays.asList(true, false, true), false}, // XOR over odd true new Object[]{Arrays.asList(true, false, false), true}, // XOR over single true new Object[]{Arrays.asList(false, false, false), false}, // XOR over all false new Object[]{Arrays.asList(true, true), false} // XOR over even true @@ -82,7 +82,7 @@ static Stream provideXorGateTestCases() { } static Stream provideNandGateTestCases() { - return Stream.of(new Object[]{Arrays.asList(true, true, true), false}, // NAND of all true is false + return Stream.of(new Object[] {Arrays.asList(true, true, true), false}, // NAND of all true is false new Object[]{Arrays.asList(true, false), true}, // NAND with one false is true new Object[]{Arrays.asList(false, false), true}, // NAND of all false is true new Object[]{Collections.emptyList(), false} // NAND over no inputs is false (negation of AND) @@ -90,7 +90,7 @@ static Stream provideNandGateTestCases() { } static Stream provideNorGateTestCases() { - return Stream.of(new Object[]{Arrays.asList(false, false),true}, // NOR of all false is true + return Stream.of(new Object[] {Arrays.asList(false, false),true}, // NOR of all false is true new Object[]{Arrays.asList(false, true), false}, // NOR with one true is false new Object[]{Arrays.asList(true, true), false}, // NOR of all true is false new Object[]{Collections.emptyList(), true} // NOR over no inputs is true (negation of OR) From b374db86f6eb69e3e3a3e727d87a060217f2aa5e Mon Sep 17 00:00:00 2001 From: vansh kabra Date: Sat, 12 Oct 2024 10:39:23 +0530 Subject: [PATCH 12/14] Add algo for BooleanGateslogic and test cases and spaces --- .../BooleanAlgebraGatesTest.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java b/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java index b8a2afc28315..e7bdcaa2fb04 100644 --- a/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java +++ b/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java @@ -64,36 +64,36 @@ void testNORGate(List inputs, boolean expected) { // Helper methods to provide test data for each gate static Stream provideAndGateTestCases() { - return Stream.of(new Object[] {Arrays.asList(true, true, true), true}, new Object[]{Arrays.asList(true, false, true), false}, new Object[]{Arrays.asList(false, false, false), false}, new Object[]{Collections.emptyList(), true} // AND over no inputs is true + return Stream.of(new Object[] {Arrays.asList(true, true, true), true}, new Object[] {Arrays.asList(true, false, true), false}, new Object[] {Arrays.asList(false, false, false), false}, new Object[] {Collections.emptyList(), true} // AND over no inputs is true ); } static Stream provideOrGateTestCases() { - return Stream.of(new Object[] {Arrays.asList(true, false, false), true}, new Object[]{Arrays.asList(false, false, false), false}, new Object[]{Arrays.asList(true, true, true), true}, new Object[]{Collections.emptyList(), false} // OR over no inputs is false + return Stream.of(new Object[] {Arrays.asList(true, false, false), true}, new Object[] {Arrays.asList(false, false, false), false}, new Object[] {Arrays.asList(true, true, true), true}, new Object[] {Collections.emptyList(), false} // OR over no inputs is false ); } static Stream provideXorGateTestCases() { return Stream.of(new Object[] {Arrays.asList(true, false, true), false}, // XOR over odd true - new Object[]{Arrays.asList(true, false, false), true}, // XOR over single true - new Object[]{Arrays.asList(false, false, false), false}, // XOR over all false - new Object[]{Arrays.asList(true, true), false} // XOR over even true + new Object[] {Arrays.asList(true, false, false), true}, // XOR over single true + new Object[] {Arrays.asList(false, false, false), false}, // XOR over all false + new Object[] {Arrays.asList(true, true), false} // XOR over even true ); } static Stream provideNandGateTestCases() { return Stream.of(new Object[] {Arrays.asList(true, true, true), false}, // NAND of all true is false - new Object[]{Arrays.asList(true, false), true}, // NAND with one false is true - new Object[]{Arrays.asList(false, false), true}, // NAND of all false is true - new Object[]{Collections.emptyList(), false} // NAND over no inputs is false (negation of AND) + new Object[] {Arrays.asList(true, false), true}, // NAND with one false is true + new Object[] {Arrays.asList(false, false), true}, // NAND of all false is true + new Object[] {Collections.emptyList(), false} // NAND over no inputs is false (negation of AND) ); } static Stream provideNorGateTestCases() { - return Stream.of(new Object[] {Arrays.asList(false, false),true}, // NOR of all false is true - new Object[]{Arrays.asList(false, true), false}, // NOR with one true is false - new Object[]{Arrays.asList(true, true), false}, // NOR of all true is false - new Object[]{Collections.emptyList(), true} // NOR over no inputs is true (negation of OR) + return Stream.of(new Object[] {Arrays.asList(false, false), true}, // NOR of all false is true + new Object[] {Arrays.asList(false, true), false}, // NOR with one true is false + new Object[] {Arrays.asList(true, true), false}, // NOR of all true is false + new Object[] {Collections.emptyList(), true} // NOR over no inputs is true (negation of OR) ); } } From 2fc4858a7d88a3c38238a9692e4a20d5d7a75397 Mon Sep 17 00:00:00 2001 From: vansh kabra Date: Sat, 12 Oct 2024 14:41:35 +0530 Subject: [PATCH 13/14] Add algo for BooleanGateslogic and test cases and spaces --- .../BooleanAlgebraGatesTest.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java b/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java index e7bdcaa2fb04..2cdc0c51198c 100644 --- a/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java +++ b/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java @@ -64,36 +64,36 @@ void testNORGate(List inputs, boolean expected) { // Helper methods to provide test data for each gate static Stream provideAndGateTestCases() { - return Stream.of(new Object[] {Arrays.asList(true, true, true), true}, new Object[] {Arrays.asList(true, false, true), false}, new Object[] {Arrays.asList(false, false, false), false}, new Object[] {Collections.emptyList(), true} // AND over no inputs is true + return Stream.of(new Object[] {Arrays.asList(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE), Boolean.TRUE}, new Object[] {Arrays.asList(Boolean.TRUE, Boolean.FALSE, Boolean.TRUE), Boolean.FALSE}, new Object[] {Arrays.asList(Boolean.FALSE, Boolean.FALSE, Boolean.FALSE), Boolean.FALSE}, new Object[] {Collections.emptyList(), Boolean.TRUE} // AND over no inputs is true ); } static Stream provideOrGateTestCases() { - return Stream.of(new Object[] {Arrays.asList(true, false, false), true}, new Object[] {Arrays.asList(false, false, false), false}, new Object[] {Arrays.asList(true, true, true), true}, new Object[] {Collections.emptyList(), false} // OR over no inputs is false + return Stream.of(new Object[] {Arrays.asList(Boolean.TRUE, Boolean.FALSE, Boolean.FALSE), Boolean.TRUE}, new Object[] {Arrays.asList(Boolean.FALSE, Boolean.FALSE, Boolean.FALSE), Boolean.FALSE}, new Object[] {Arrays.asList(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE), Boolean.TRUE}, new Object[] {Collections.emptyList(), Boolean.FALSE} // OR over no inputs is false ); } static Stream provideXorGateTestCases() { - return Stream.of(new Object[] {Arrays.asList(true, false, true), false}, // XOR over odd true - new Object[] {Arrays.asList(true, false, false), true}, // XOR over single true - new Object[] {Arrays.asList(false, false, false), false}, // XOR over all false - new Object[] {Arrays.asList(true, true), false} // XOR over even true + return Stream.of(new Object[] {Arrays.asList(Boolean.TRUE, Boolean.FALSE, Boolean.TRUE), Boolean.FALSE}, // XOR over odd true + new Object[] {Arrays.asList(Boolean.TRUE, Boolean.FALSE, Boolean.FALSE), Boolean.TRUE}, // XOR over single true + new Object[] {Arrays.asList(Boolean.FALSE, Boolean.FALSE, Boolean.FALSE), Boolean.FALSE}, // XOR over all false + new Object[] {Arrays.asList(Boolean.TRUE, Boolean.TRUE), Boolean.FALSE} // XOR over even true ); } static Stream provideNandGateTestCases() { - return Stream.of(new Object[] {Arrays.asList(true, true, true), false}, // NAND of all true is false - new Object[] {Arrays.asList(true, false), true}, // NAND with one false is true - new Object[] {Arrays.asList(false, false), true}, // NAND of all false is true - new Object[] {Collections.emptyList(), false} // NAND over no inputs is false (negation of AND) + return Stream.of(new Object[] {Arrays.asList(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE), Boolean.FALSE}, // NAND of all true is false + new Object[] {Arrays.asList(Boolean.TRUE, Boolean.FALSE), Boolean.TRUE}, // NAND with one false is true + new Object[] {Arrays.asList(Boolean.FALSE, Boolean.FALSE), Boolean.TRUE}, // NAND of all false is true + new Object[] {Collections.emptyList(), Boolean.FALSE} // NAND over no inputs is false (negation of AND) ); } static Stream provideNorGateTestCases() { - return Stream.of(new Object[] {Arrays.asList(false, false), true}, // NOR of all false is true - new Object[] {Arrays.asList(false, true), false}, // NOR with one true is false - new Object[] {Arrays.asList(true, true), false}, // NOR of all true is false - new Object[] {Collections.emptyList(), true} // NOR over no inputs is true (negation of OR) + return Stream.of(new Object[] {Arrays.asList(Boolean.FALSE, Boolean.FALSE), Boolean.TRUE}, // NOR of all false is true + new Object[] {Arrays.asList(Boolean.FALSE, Boolean.TRUE), Boolean.FALSE}, // NOR with one true is false + new Object[] {Arrays.asList(Boolean.TRUE, Boolean.TRUE), Boolean.FALSE}, // NOR of all true is false + new Object[] {Collections.emptyList(), Boolean.TRUE} // NOR over no inputs is true (negation of OR) ); } } From 620907768f9b335095cadc53e35e6930238dacae Mon Sep 17 00:00:00 2001 From: vansh kabra Date: Sat, 12 Oct 2024 14:46:29 +0530 Subject: [PATCH 14/14] Add algo for BooleanGateslogic and test cases and spaces and booleans --- .../bitmanipulation/BooleanAlgebraGatesTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java b/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java index 2cdc0c51198c..8737d05ec459 100644 --- a/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java +++ b/src/test/java/com/thealgorithms/bitmanipulation/BooleanAlgebraGatesTest.java @@ -64,12 +64,14 @@ void testNORGate(List inputs, boolean expected) { // Helper methods to provide test data for each gate static Stream provideAndGateTestCases() { - return Stream.of(new Object[] {Arrays.asList(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE), Boolean.TRUE}, new Object[] {Arrays.asList(Boolean.TRUE, Boolean.FALSE, Boolean.TRUE), Boolean.FALSE}, new Object[] {Arrays.asList(Boolean.FALSE, Boolean.FALSE, Boolean.FALSE), Boolean.FALSE}, new Object[] {Collections.emptyList(), Boolean.TRUE} // AND over no inputs is true + return Stream.of(new Object[] {Arrays.asList(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE), Boolean.TRUE}, new Object[] {Arrays.asList(Boolean.TRUE, Boolean.FALSE, Boolean.TRUE), Boolean.FALSE}, new Object[] {Arrays.asList(Boolean.FALSE, Boolean.FALSE, Boolean.FALSE), Boolean.FALSE}, + new Object[] {Collections.emptyList(), Boolean.TRUE} // AND over no inputs is true ); } static Stream provideOrGateTestCases() { - return Stream.of(new Object[] {Arrays.asList(Boolean.TRUE, Boolean.FALSE, Boolean.FALSE), Boolean.TRUE}, new Object[] {Arrays.asList(Boolean.FALSE, Boolean.FALSE, Boolean.FALSE), Boolean.FALSE}, new Object[] {Arrays.asList(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE), Boolean.TRUE}, new Object[] {Collections.emptyList(), Boolean.FALSE} // OR over no inputs is false + return Stream.of(new Object[] {Arrays.asList(Boolean.TRUE, Boolean.FALSE, Boolean.FALSE), Boolean.TRUE}, new Object[] {Arrays.asList(Boolean.FALSE, Boolean.FALSE, Boolean.FALSE), Boolean.FALSE}, new Object[] {Arrays.asList(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE), Boolean.TRUE}, + new Object[] {Collections.emptyList(), Boolean.FALSE} // OR over no inputs is false ); }