-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParserNotCountTest.java
35 lines (30 loc) · 1.09 KB
/
ParserNotCountTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package expression.parser;
import java.util.Arrays;
/**
* @author Georgiy Korneev
*/
public class ParserNotCountTest extends ParserBitwiseTest {
protected ParserNotCountTest() {
unary.add(op("~", a -> ~a));
unary.add(op("count", ParserNotCountTest::count));
tests.addAll(Arrays.asList(
op("~-5", (x, y, z) -> 4),
op("~(x - y)", (x, y, z) -> ~(x - y)),
op("x-~-y", (x, y, z) -> x - ~(-y)),
op("~-x", (x, y, z) -> ~(-x)),
op("~(x+y)", (x, y, z) -> ~(x + y)),
op("count 5", (x, y, z) -> 2),
op("count -5", (x, y, z) -> 31),
op("count (x - y)", (x, y, z) -> count(x - y)),
op("x -count y", (x, y, z) -> x - count(y)),
op("count -x", (x, y, z) -> count(-x)),
op("count(x+y)", (x, y, z) -> count(x + y))
));
}
public static long count(final long a) {
return Integer.bitCount((int) a);
}
public static void main(final String[] args) {
new ParserNotCountTest().run();
}
}