MCPcopy Create free account
hub / github.com/blues/note / TestOLCEncodingRoundTrip

Function TestOLCEncodingRoundTrip

lib/bulk_test.go:595–711  ·  view source on GitHub ↗

TestOLCEncodingRoundTrip tests that OLC values round-trip correctly through encoding/decoding

(t *testing.T)

Source from the content-addressed store, hash-verified

593
594// TestOLCEncodingRoundTrip tests that OLC values round-trip correctly through encoding/decoding
595func TestOLCEncodingRoundTrip(t *testing.T) {
596 // Test location: Blues Inc headquarters in Boston (approximately)
597 testLat := 42.3601
598 testLon := -71.0589
599 testOLC := golc.Encode(testLat, testLon, 12)
600
601 tests := []struct {
602 name string
603 templateField string
604 expectedMaxError float64 // in meters
605 }{
606 {
607 name: "OLC8 - Full 8-byte precision",
608 templateField: "_loc8",
609 expectedMaxError: 0.1, // Perfect
610 },
611 {
612 name: "OLC7 - 7-byte precision (12 chars)",
613 templateField: "_loc7",
614 expectedMaxError: 2, // ~1.7m measured
615 },
616 {
617 name: "OLC6 - 6-byte precision (10 chars)",
618 templateField: "_loc6",
619 expectedMaxError: 20, // ~18m measured
620 },
621 {
622 name: "OLC5 - 5-byte precision (8 chars, coarse grid only)",
623 templateField: "_loc5",
624 expectedMaxError: 130, // ~128m measured
625 },
626 {
627 name: "OLC4 - 4-byte precision (7 chars, truncated coarse)",
628 templateField: "_loc4",
629 expectedMaxError: 1500, // ~1226m measured
630 },
631 }
632
633 for _, tt := range tests {
634 ctx := context.Background()
635 t.Run(tt.name, func(t *testing.T) {
636 // Create template with the OLC field (use FlexNano to avoid compression)
637 templateBody := BulkBody{
638 NoteFormat: BulkNoteFormatFlexNano,
639 NoteTemplate: fmt.Sprintf(`{"%s": 18, "data": 14}`, tt.templateField),
640 }
641 templateJSON, err := note.JSONMarshal(templateBody)
642 require.NoError(t, err)
643
644 // Create test data
645 testData := map[string]interface{}{
646 "data": 42,
647 }
648
649 // Encode with OLC
650 encodeCtx, err := BulkEncodeTemplate(templateJSON)
651 require.NoError(t, err)
652

Callers

nothing calls this directly

Calls 8

BulkEncodeTemplateFunction · 0.85
BulkDecodeTemplateFunction · 0.85
haversineDistanceFunction · 0.85
BulkEncodeNextEntryMethod · 0.80
BulkDecodeNextEntryMethod · 0.80
Int64Method · 0.80
EncodeMethod · 0.45
DecodeMethod · 0.45

Tested by

no test coverage detected