-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_functionality.py
More file actions
84 lines (71 loc) · 2.69 KB
/
test_functionality.py
File metadata and controls
84 lines (71 loc) · 2.69 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
"""
Test script to verify UnForkRAG functionality
"""
import sys
sys.path.insert(0, '.')
print("=" * 60)
print("UnForkRAG Functionality Tests")
print("=" * 60)
# Test 1: GDA Hash
print("\n[TEST 1] GDA Hash Implementation")
from gda_hash import gda_hash, GdaPositionIndex
hash_val = gda_hash('hello')
print(f" gda_hash('hello') = {hash_val} (0x{hash_val:06x})")
print(f" Hash is 24-bit (0-16,777,215): {0 <= hash_val < 2**24}")
index = GdaPositionIndex(size=16777216) # Full 24-bit address space
index.add('hello', 0)
index.add('world', 1)
index.add('hello', 5)
positions = index.get('hello')
print(f" Position index working: {positions == [0, 5]}")
# Test 2: Code Tokenizer
print("\n[TEST 2] Code Tokenizer")
from code_tokenizer import tokenize_code, tokenize_text, is_prose, detect_language
code = '''
def getUserProfile(user_id: int) -> dict:
"""Fetch user profile from database."""
user = db.query("SELECT * FROM users WHERE id = ?", user_id)
return {"name": user.name, "email": user.email}
'''
tokens = tokenize_code(code)
print(f" Code tokens extracted: {len(tokens)} tokens")
print(f" First 5: {tokens[:5]}")
lang = detect_language(code)
print(f" Language detection: {lang}")
prose = 'The quick brown fox jumps over the lazy dog.'
print(f" Prose detection (prose): {is_prose(prose)}")
print(f" Prose detection (code): {is_prose(code)}")
# Test 3: Synsets
print("\n[TEST 3] Synsets")
from synsets import Synsets
synsets = Synsets()
synsets.add_group(['fast', 'quick', 'rapid', 'speedy'])
expanded = synsets.expand('fast')
print(f" Synset expansion for 'fast': {expanded}")
# Test 4: Chroma Compatibility
print("\n[TEST 4] Chroma Compatibility Layer")
from chroma_compat import UnForkClient, UnForkCollection
client = UnForkClient()
collection = client.create_collection('test')
print(f" Created collection: {collection.name}")
collection.add(
ids=['doc1', 'doc2'],
documents=['def hello(): pass', 'The quick brown fox'],
metadatas=[{'type': 'code'}, {'type': 'prose'}]
)
print(f" Added documents: {collection.count()}")
results = collection.query(query_texts=['function'], n_results=2)
print(f" Search results: {len(results['ids'][0])} documents")
# Test 5: Inferred Relations
print("\n[TEST 5] Inferred Relations")
from inferred_relations import InferredRelations
relations = InferredRelations({}, [], use_gda=True)
relations.add_token('hello', 0)
relations.add_token('world', 1)
relations.add_token('hello', 5)
positions = relations.get_positions('hello')
print(f" GDA positions for 'hello': {positions}")
print("\n" + "=" * 60)
print("All Tests Completed Successfully!")
print("=" * 60)