diff --git a/compile.go b/compile.go index bf7b308..38d8c11 100644 --- a/compile.go +++ b/compile.go @@ -5,8 +5,8 @@ const ( ) const ( - maskfirst = 0b0111111111111111111111111111111111111111000000000000000000000000 - masksecond = 0b0000000000000000000000000000000000000000111111111111111111111111 + maskunixtime = 0b0111111111111111111111111111111111111111000000000000000000000000 + maskchaos = 0b0000000000000000000000000000000000000000111111111111111111111111 ) const ( @@ -16,7 +16,7 @@ const ( func compile(first uint64, second uint64) uint64 { - var compiled uint64 = ((first << widthsecond) & maskfirst) | (second & masksecond) + var compiled uint64 = ((first << widthsecond) & maskunixtime) | (second & maskchaos) return compiled @@ -24,8 +24,8 @@ func compile(first uint64, second uint64) uint64 { func decompile(value uint64) (uint64, uint64) { - var first uint64 = (value & maskfirst) >> widthsecond - var second uint64 = value & masksecond + var first uint64 = (value & maskunixtime) >> widthsecond + var second uint64 = value & maskchaos return first, second } diff --git a/parse_test.go b/parse_test.go new file mode 100644 index 0000000..a92801e --- /dev/null +++ b/parse_test.go @@ -0,0 +1,58 @@ +package xim + +import ( + "testing" +) + +func TestParse(t *testing.T) { + + for testNumber, test := range stdtests { + + var id ID = something(test.Value) + + var ximid string = id.String() + + var actual ID = Parse(ximid) + if Nothing() == actual { + t.Errorf("For test #%d, the actual result of parsing is not what was expected — it is option-type value nothing" , testNumber) + t.Logf("VALUE: %#064b", test.Value) + t.Logf("ID: %s", id) + { + chaos, successful := id.Chaos() + t.Logf("ID-CHAOS-SUCCESSFUL: %t", successful) + t.Logf("ID-CHAOS: %#064b", chaos) + } + t.Logf("XIM-ID: %s", ximid) + t.Logf("ACTUAL: %s", actual) + continue + } + + { + actualchaos, successful := id.Chaos() + if !successful { + t.Errorf("For test #%d, the actual result of parsing is not what was expected — it is option-type value nothing" , testNumber) + t.Logf("VALUE: %#064b", test.Value) + t.Logf("ID: %s", id) + { + chaos, successful := id.Chaos() + t.Logf("ID-CHAOS-SUCCESSFUL: %t", successful) + t.Logf("ID-CHAOS: %#064b", chaos) + } + t.Logf("XIM-ID: %s", ximid) + t.Logf("ACTUAL: %s", actual) + continue + } + + if expectedchaos := test.Value & maskchaos; expectedchaos != actualchaos { + t.Errorf("For test #%d, the chaos from the actual result of parsing is not what was expected" , testNumber) + t.Logf("VALUE: %#064b", test.Value) + t.Logf("ID: %s", id) + t.Logf("XIM-ID: %s", ximid) + t.Logf("ACTUAL: %s", actual) + t.Logf("ACTUAL-CHAOS: %#064b", actualchaos) + t.Logf("EXPECTED-CHAOS: %#064b", expectedchaos) + continue + } + } + } +}