github.com/susy-go/susy-graviton@v0.0.0-20190614130430-36cddae42305/swarm/storage/feed/lookup/epoch_test.go (about) 1 package lookup_test 2 3 import ( 4 "testing" 5 6 "github.com/susy-go/susy-graviton/swarm/storage/feed/lookup" 7 ) 8 9 func TestMarshallers(t *testing.T) { 10 11 for i := uint64(1); i < lookup.MaxTime; i *= 3 { 12 e := lookup.Epoch{ 13 Time: i, 14 Level: uint8(i % 20), 15 } 16 b, err := e.MarshalBinary() 17 if err != nil { 18 t.Fatal(err) 19 } 20 var e2 lookup.Epoch 21 if err := e2.UnmarshalBinary(b); err != nil { 22 t.Fatal(err) 23 } 24 if e != e2 { 25 t.Fatal("Expected unmarshalled epoch to be equal to marshalled onet.Fatal(err)") 26 } 27 } 28 29 } 30 31 func TestAfter(t *testing.T) { 32 a := lookup.Epoch{ 33 Time: 5, 34 Level: 3, 35 } 36 b := lookup.Epoch{ 37 Time: 6, 38 Level: 3, 39 } 40 c := lookup.Epoch{ 41 Time: 6, 42 Level: 4, 43 } 44 45 if !b.After(a) { 46 t.Fatal("Expected 'after' to be true, got false") 47 } 48 49 if b.After(b) { 50 t.Fatal("Expected 'after' to be false when both epochs are identical, got true") 51 } 52 53 if !b.After(c) { 54 t.Fatal("Expected 'after' to be true when both epochs have the same time but the level is lower in the first one, but got false") 55 } 56 57 }