diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 22:40:55 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 22:40:55 +0100 |
| commit | 5d8dfe892a2ea89f706ee140c3bdcfd89fe03fda (patch) | |
| tree | 1acdfa5220cd13b7be43a2a01368e80d306473ca /examples/redis-unstable/modules/vector-sets/tests/vismember.py | |
| parent | c7ab12bba64d9c20ccd79b132dac475f7bc3923e (diff) | |
| download | crep-5d8dfe892a2ea89f706ee140c3bdcfd89fe03fda.tar.gz | |
Add Redis source code for testing
Diffstat (limited to 'examples/redis-unstable/modules/vector-sets/tests/vismember.py')
| -rw-r--r-- | examples/redis-unstable/modules/vector-sets/tests/vismember.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/examples/redis-unstable/modules/vector-sets/tests/vismember.py b/examples/redis-unstable/modules/vector-sets/tests/vismember.py new file mode 100644 index 0000000..eabebca --- /dev/null +++ b/examples/redis-unstable/modules/vector-sets/tests/vismember.py | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | from test import TestCase, generate_random_vector | ||
| 2 | import struct | ||
| 3 | |||
| 4 | class BasicVISMEMBER(TestCase): | ||
| 5 | def getname(self): | ||
| 6 | return "VISMEMBER basic functionality" | ||
| 7 | |||
| 8 | def test(self): | ||
| 9 | # Add multiple vectors to the vector set | ||
| 10 | vec1 = generate_random_vector(4) | ||
| 11 | vec2 = generate_random_vector(4) | ||
| 12 | vec_bytes1 = struct.pack('4f', *vec1) | ||
| 13 | vec_bytes2 = struct.pack('4f', *vec2) | ||
| 14 | |||
| 15 | # Create item keys | ||
| 16 | item1 = f'{self.test_key}:item:1' | ||
| 17 | item2 = f'{self.test_key}:item:2' | ||
| 18 | nonexistent_item = f'{self.test_key}:item:nonexistent' | ||
| 19 | |||
| 20 | # Add the vectors | ||
| 21 | self.redis.execute_command('VADD', self.test_key, 'FP32', vec_bytes1, item1) | ||
| 22 | self.redis.execute_command('VADD', self.test_key, 'FP32', vec_bytes2, item2) | ||
| 23 | |||
| 24 | # Test VISMEMBER with existing elements | ||
| 25 | result1 = self.redis.execute_command('VISMEMBER', self.test_key, item1) | ||
| 26 | assert result1 == 1, f"VISMEMBER should return 1 for existing item, got {result1}" | ||
| 27 | |||
| 28 | result2 = self.redis.execute_command('VISMEMBER', self.test_key, item2) | ||
| 29 | assert result2 == 1, f"VISMEMBER should return 1 for existing item, got {result2}" | ||
| 30 | |||
| 31 | # Test VISMEMBER with non-existent element | ||
| 32 | result3 = self.redis.execute_command('VISMEMBER', self.test_key, nonexistent_item) | ||
| 33 | assert result3 == 0, f"VISMEMBER should return 0 for non-existent item, got {result3}" | ||
| 34 | |||
| 35 | # Test VISMEMBER with non-existent key | ||
| 36 | nonexistent_key = f'{self.test_key}_nonexistent' | ||
| 37 | result4 = self.redis.execute_command('VISMEMBER', nonexistent_key, item1) | ||
| 38 | assert result4 == 0, f"VISMEMBER should return 0 for non-existent key, got {result4}" | ||
| 39 | |||
| 40 | # Test VISMEMBER after removing an element | ||
| 41 | self.redis.execute_command('VREM', self.test_key, item1) | ||
| 42 | result5 = self.redis.execute_command('VISMEMBER', self.test_key, item1) | ||
| 43 | assert result5 == 0, f"VISMEMBER should return 0 after element removal, got {result5}" | ||
| 44 | |||
| 45 | # Verify item2 still exists | ||
| 46 | result6 = self.redis.execute_command('VISMEMBER', self.test_key, item2) | ||
| 47 | assert result6 == 1, f"VISMEMBER should still return 1 for remaining item, got {result6}" | ||
