MCPcopy Index your code
hub / github.com/codechenx/FastTableViewer / TestBufferStringInterning

Function TestBufferStringInterning

string_interning_test.go:94–140  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

92}
93
94func TestBufferStringInterning(t *testing.T) {
95 // Create test data with repeated categorical values
96 data := [][]string{
97 {"Category", "Value"},
98 {"A", "100"},
99 {"B", "200"},
100 {"A", "300"}, // Repeated
101 {"C", "400"},
102 {"A", "500"}, // Repeated
103 {"B", "600"}, // Repeated
104 }
105
106 // Add more rows to make it worthwhile
107 for i := 0; i < 100; i++ {
108 data = append(data, []string{"A", fmt.Sprintf("%d", i)})
109 data = append(data, []string{"B", fmt.Sprintf("%d", i+1000)})
110 data = append(data, []string{"C", fmt.Sprintf("%d", i+2000)})
111 }
112
113 b, err := createNewBufferWithData(data, false)
114 if err != nil {
115 t.Fatalf("Failed to create buffer: %v", err)
116 }
117
118 b.rowFreeze = 1
119
120 // Enable string interning
121 b.enableStringInterning()
122
123 // Check that interning is enabled
124 stats := b.getInterningStats()
125 if !stats["enabled"].(bool) {
126 t.Error("String interning should be enabled")
127 }
128
129 // Category column (0) should be interned (low cardinality)
130 if !b.internCols[0] {
131 t.Error("Category column should be interned")
132 }
133
134 // Value column (1) should NOT be interned (high cardinality)
135 if b.internCols[1] {
136 t.Error("Value column should not be interned")
137 }
138
139 t.Logf("Interning stats: %+v", stats)
140}
141
142func TestStringInterningMemorySavings(t *testing.T) {
143 // Create large dataset with repeated values

Callers

nothing calls this directly

Calls 3

createNewBufferWithDataFunction · 0.85
enableStringInterningMethod · 0.80
getInterningStatsMethod · 0.80

Tested by

no test coverage detected