[DEPRECATED] Go implementation of plcbundle
at rust-test 58 lines 1.5 kB view raw
1package didindex_test 2 3import ( 4 "testing" 5 6 "tangled.org/atscan.net/plcbundle/internal/didindex" 7) 8 9func TestOpLocationPacking(t *testing.T) { 10 tests := []struct { 11 bundle uint16 12 position uint16 13 nullified bool 14 }{ 15 {1, 0, false}, 16 {1, 9999, false}, 17 {100, 5000, true}, 18 {65535, 9999, true}, // Max values 19 } 20 21 for _, tt := range tests { 22 loc := didindex.NewOpLocation(tt.bundle, tt.position, tt.nullified) 23 24 // Test unpacking 25 if loc.Bundle() != tt.bundle { 26 t.Errorf("Bundle mismatch: got %d, want %d", loc.Bundle(), tt.bundle) 27 } 28 if loc.Position() != tt.position { 29 t.Errorf("Position mismatch: got %d, want %d", loc.Position(), tt.position) 30 } 31 if loc.Nullified() != tt.nullified { 32 t.Errorf("Nullified mismatch: got %v, want %v", loc.Nullified(), tt.nullified) 33 } 34 35 // Test global position 36 expectedGlobal := uint32(tt.bundle)*10000 + uint32(tt.position) 37 if loc.GlobalPosition() != expectedGlobal { 38 t.Errorf("Global position mismatch: got %d, want %d", 39 loc.GlobalPosition(), expectedGlobal) 40 } 41 } 42} 43 44func TestOpLocationComparison(t *testing.T) { 45 loc1 := didindex.NewOpLocation(100, 50, false) // 1,000,050 46 loc2 := didindex.NewOpLocation(100, 51, false) // 1,000,051 47 loc3 := didindex.NewOpLocation(200, 30, false) // 2,000,030 48 49 if !loc1.Less(loc2) { 50 t.Error("Expected loc1 < loc2") 51 } 52 if !loc2.Less(loc3) { 53 t.Error("Expected loc2 < loc3") 54 } 55 if loc3.Less(loc1) { 56 t.Error("Expected loc3 > loc1") 57 } 58}