blob: f071c5da921dba33828e7c7c2bba89504bd1cd16 (
plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
test("basic numeric shifting", () => {
expect(0 >> 0).toBe(0);
expect(0 >> 1).toBe(0);
expect(0 >> 2).toBe(0);
expect(0 >> 3).toBe(0);
expect(0 >> 4).toBe(0);
expect(0 >> 5).toBe(0);
expect(1 >> 0).toBe(1);
expect(1 >> 1).toBe(0);
expect(1 >> 2).toBe(0);
expect(1 >> 3).toBe(0);
expect(1 >> 4).toBe(0);
expect(1 >> 5).toBe(0);
expect(5 >> 0).toBe(5);
expect(5 >> 1).toBe(2);
expect(5 >> 2).toBe(1);
expect(5 >> 3).toBe(0);
expect(5 >> 4).toBe(0);
expect(5 >> 5).toBe(0);
expect(42 >> 0).toBe(42);
expect(42 >> 1).toBe(21);
expect(42 >> 2).toBe(10);
expect(42 >> 3).toBe(5);
expect(42 >> 4).toBe(2);
expect(42 >> 5).toBe(1);
});
test("numeric shifting with negative lhs values", () => {
expect(-1 >> 0).toBe(-1);
expect(-1 >> 1).toBe(-1);
expect(-1 >> 2).toBe(-1);
expect(-1 >> 3).toBe(-1);
expect(-1 >> 4).toBe(-1);
expect(-1 >> 5).toBe(-1);
expect(-5 >> 0).toBe(-5);
expect(-5 >> 1).toBe(-3);
expect(-5 >> 2).toBe(-2);
expect(-5 >> 3).toBe(-1);
expect(-5 >> 4).toBe(-1);
expect(-5 >> 5).toBe(-1);
});
test("shifting with non-numeric values", () => {
let x = 67;
let y = 4;
expect("42" >> 3).toBe(5);
expect(x >> y).toBe(4);
expect(x >> [[[[5]]]]).toBe(2);
expect(undefined >> y).toBe(0);
expect("a" >> "b").toBe(0);
expect(null >> null).toBe(0);
expect(undefined >> undefined).toBe(0);
expect(NaN >> NaN).toBe(0);
expect(6 >> NaN).toBe(6);
expect(Infinity >> Infinity).toBe(0);
expect(-Infinity >> Infinity).toBe(0);
});
|