Skip to content

Commit 1b7c5cc

Browse files
authored
Fix binary value in comment in test code (#3402)
* Fix binary value in comment in test code src/test/java/redis/clients/jedis/commands/jedis/BitCommandsTest.java When first setting "0" (string) to redis, the bits are actually 0011 0000, instead of number 0 with bits 0000 0000. Goods new is: all the code logic are correct. The problem only exists in the comment. For convenience, I have some helper code to print bits and their positions (10-based), which makes bit navigation easier. e.g. The final bits are: ``` 0011 0001 0000 0100 0000 0000 0000 0000 0000 0001 0123 4567 8901 2345 6789 0123 4567 8901 2345 6789 0 1 2 3 4 ```
1 parent 104c55b commit 1b7c5cc

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/test/java/redis/clients/jedis/commands/jedis/BitCommandsTest.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@ public void bitpos() {
3535
String foo = "foo";
3636

3737
jedis.set(foo, String.valueOf(0));
38+
// string "0" with bits: 0011 0000
3839

3940
jedis.setbit(foo, 3, true);
4041
jedis.setbit(foo, 7, true);
4142
jedis.setbit(foo, 13, true);
4243
jedis.setbit(foo, 39, true);
4344

4445
/*
45-
* byte: 0 1 2 3 4 bit: 00010001 / 00000100 / 00000000 / 00000000 / 00000001
46+
* bit: 00110001 / 00000100 / 00000000 / 00000000 / 00000001
47+
* byte: 0 1 2 3 4
4648
*/
4749
long offset = jedis.bitpos(foo, true);
4850
assertEquals(2, offset);
@@ -69,14 +71,16 @@ public void bitposBinary() {
6971
byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
7072

7173
jedis.set(bfoo, Protocol.toByteArray(0));
74+
// bits: 0011 0000
7275

7376
jedis.setbit(bfoo, 3, true);
7477
jedis.setbit(bfoo, 7, true);
7578
jedis.setbit(bfoo, 13, true);
7679
jedis.setbit(bfoo, 39, true);
7780

7881
/*
79-
* byte: 0 1 2 3 4 bit: 00010001 / 00000100 / 00000000 / 00000000 / 00000001
82+
* bit: 00110001 / 00000100 / 00000000 / 00000000 / 00000001
83+
* byte: 0 1 2 3 4
8084
*/
8185
long offset = jedis.bitpos(bfoo, true);
8286
assertEquals(2, offset);
@@ -107,7 +111,8 @@ public void bitposWithNoMatchingBitExist() {
107111
}
108112

109113
/*
110-
* byte: 0 bit: 11111111
114+
* bit: 11111111
115+
* byte: 0
111116
*/
112117
long offset = jedis.bitpos(foo, false);
113118
// offset should be last index + 1
@@ -124,7 +129,8 @@ public void bitposWithNoMatchingBitExistWithinRange() {
124129
}
125130

126131
/*
127-
* byte: 0 1 2 3 4 bit: 11111111 / 11111111 / 11111111 / 11111111 / 11111111
132+
* bit: 11111111 / 11111111 / 11111111 / 11111111 / 11111111
133+
* byte: 0 1 2 3 4
128134
*/
129135
long offset = jedis.bitpos(foo, false, new BitPosParams(2, 3));
130136
// offset should be -1

src/test/java/redis/clients/jedis/commands/unified/BitCommandsTestBase.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@ public void bitpos() {
3535
String foo = "foo";
3636

3737
jedis.set(foo, String.valueOf(0));
38+
// string "0" with bits: 0011 0000
3839

3940
jedis.setbit(foo, 3, true);
4041
jedis.setbit(foo, 7, true);
4142
jedis.setbit(foo, 13, true);
4243
jedis.setbit(foo, 39, true);
4344

4445
/*
45-
* byte: 0 1 2 3 4 bit: 00010001 / 00000100 / 00000000 / 00000000 / 00000001
46+
* bit: 00110001 / 00000100 / 00000000 / 00000000 / 00000001
47+
* byte: 0 1 2 3 4
4648
*/
4749
long offset = jedis.bitpos(foo, true);
4850
assertEquals(2, offset);
@@ -69,14 +71,16 @@ public void bitposBinary() {
6971
byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
7072

7173
jedis.set(bfoo, Protocol.toByteArray(0));
74+
// bits: 0011 0000
7275

7376
jedis.setbit(bfoo, 3, true);
7477
jedis.setbit(bfoo, 7, true);
7578
jedis.setbit(bfoo, 13, true);
7679
jedis.setbit(bfoo, 39, true);
7780

7881
/*
79-
* byte: 0 1 2 3 4 bit: 00010001 / 00000100 / 00000000 / 00000000 / 00000001
82+
* bit: 00110001 / 00000100 / 00000000 / 00000000 / 00000001
83+
* byte: 0 1 2 3 4
8084
*/
8185
long offset = jedis.bitpos(bfoo, true);
8286
assertEquals(2, offset);
@@ -107,7 +111,8 @@ public void bitposWithNoMatchingBitExist() {
107111
}
108112

109113
/*
110-
* byte: 0 bit: 11111111
114+
* bit: 11111111
115+
* byte: 0
111116
*/
112117
long offset = jedis.bitpos(foo, false);
113118
// offset should be last index + 1
@@ -124,7 +129,8 @@ public void bitposWithNoMatchingBitExistWithinRange() {
124129
}
125130

126131
/*
127-
* byte: 0 1 2 3 4 bit: 11111111 / 11111111 / 11111111 / 11111111 / 11111111
132+
* bit: 11111111 / 11111111 / 11111111 / 11111111 / 11111111
133+
* byte: 0 1 2 3 4
128134
*/
129135
long offset = jedis.bitpos(foo, false, new BitPosParams(2, 3));
130136
// offset should be -1

0 commit comments

Comments
 (0)