MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / TestBitcount

Function TestBitcount

IceFireDB-PubSub/test/cmd_string_test.go:1102–1173  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1100}
1101
1102func TestBitcount(t *testing.T) {
1103 server.Clear()
1104 c, err := proto.Dial(server.Addr())
1105 ok(t, err)
1106 defer c.Close()
1107 s := server.Direct()
1108
1109 {
1110 s.Set("countme", "a") // 'a' is 0x1100001
1111 mustDo(t, c,
1112 "BITCOUNT", "countme",
1113 proto.Int(3),
1114 )
1115
1116 s.Set("countme", "aaaaa") // 'a' is 0x1100001
1117 mustDo(t, c,
1118 "BITCOUNT", "countme",
1119 proto.Int(3*5),
1120 )
1121 }
1122 // Non-existing
1123 must0(t, c,
1124 "BITCOUNT", "nosuch",
1125 )
1126
1127 {
1128 // a: 0x1100001 - 3
1129 // b: 0x1100010 - 3
1130 // c: 0x1100011 - 4
1131 // d: 0x1100100 - 3
1132 s.Set("foo", "abcd")
1133 test := func(s, e, res int) {
1134 t.Helper()
1135 mustDo(t, c,
1136 "BITCOUNT", "foo", strconv.Itoa(s), strconv.Itoa(e),
1137 proto.Int(res),
1138 )
1139 }
1140 test(0, 0, 3) // "a"
1141 test(0, 3, 13) // "abcd"
1142 test(2, -2, 4) // "c"
1143 }
1144
1145 // Wrong type of existing key
1146 {
1147 s.HSet("wrong", "aap", "noot")
1148 mustDo(t, c,
1149 "BITCOUNT", "wrong",
1150 proto.Error(msgWrongType),
1151 )
1152 }
1153
1154 // Wrong usage
1155 {
1156 mustDo(t, c,
1157 "BITCOUNT",
1158 proto.Error(errWrongNumber("bitcount")),
1159 )

Callers

nothing calls this directly

Calls 12

ClearFunction · 0.92
DialFunction · 0.92
AddrFunction · 0.92
DirectFunction · 0.92
IntFunction · 0.92
ErrorFunction · 0.92
SetMethod · 0.80
okFunction · 0.70
mustDoFunction · 0.70
must0Function · 0.70
errWrongNumberFunction · 0.70
CloseMethod · 0.65

Tested by

no test coverage detected