Skip to content

Commit

Permalink
Add != operator
Browse files Browse the repository at this point in the history
  • Loading branch information
boxbeam committed Feb 13, 2022
1 parent 3bc4224 commit dfd984c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ Implicit multiplication - `xy` is identical to `x*y`, `3x` is identical to `3*x`

`false` - Boolean constant representing 0

`=` - Compare if two numbers are equal (`1 = 1` will be `1`, `1 = 3` will be 0)
`=` - Compare if two numbers are equal (`1 = 1` will be `1`, `1 = 3` will be `0`)

`!=` - Compare if two numbers are not equal (`1 != 2` will be `1`, `1 != 1` will be `0`)

`>` - Compare if one number is greater than another (`1 > 0`)

Expand Down
1 change: 1 addition & 0 deletions src/redempt/crunch/token/Operator.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum Operator implements Token {
GREATER_THAN(">", 1, (a, b) -> a > b ? 1d : 0d),
LESS_THAN("<", 1, (a, b) -> a < b ? 1d : 0d),
EQUAL_TO("=", 1, (a, b) -> a == b ? 1d : 0d),
NOT_EQUAL_TO("!=", 1, (a, b) -> a != b ? 1d : 0d),
GREATER_THAN_OR_EQUAL_TO(">=", 1, (a, b) -> a >= b ? 1d : 0d),
LESS_THAN_OR_EQUAL_TO("<=", 1, (a, b) -> a <= b ? 1d : 0d),
BOOLEAN_NOT("!", 9, d -> d == 0 ? 1d : 0d),
Expand Down
1 change: 1 addition & 0 deletions test/redempt/crunch/test/CrunchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void booleanLogicTest() {
assertEquals(1, Crunch.evaluateExpression("true | false"), "Boolean or");
assertEquals(0, Crunch.evaluateExpression("true & (true & false | false)"), "More complex boolean expression");
assertEquals(1, Crunch.evaluateExpression("1 = 1 & 3 = 3"), "Arithmetic comparisons");
assertEquals(1, Crunch.evaluateExpression("1 != 2 & 3 != 4"), "Using !=");
}

@Test
Expand Down

0 comments on commit dfd984c

Please sign in to comment.