initial commits

master
Charles Iliya Krempeaux 2021-11-08 16:27:21 -08:00
parent 0966f43755
commit 54f5d55f27
2 changed files with 63 additions and 5 deletions

View File

@ -5,8 +5,8 @@ const (
) )
const ( const (
maskfirst = 0b0111111111111111111111111111111111111111000000000000000000000000 maskunixtime = 0b0111111111111111111111111111111111111111000000000000000000000000
masksecond = 0b0000000000000000000000000000000000000000111111111111111111111111 maskchaos = 0b0000000000000000000000000000000000000000111111111111111111111111
) )
const ( const (
@ -16,7 +16,7 @@ const (
func compile(first uint64, second uint64) uint64 { 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 return compiled
@ -24,8 +24,8 @@ func compile(first uint64, second uint64) uint64 {
func decompile(value uint64) (uint64, uint64) { func decompile(value uint64) (uint64, uint64) {
var first uint64 = (value & maskfirst) >> widthsecond var first uint64 = (value & maskunixtime) >> widthsecond
var second uint64 = value & masksecond var second uint64 = value & maskchaos
return first, second return first, second
} }

58
parse_test.go 100644
View File

@ -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
}
}
}
}