rotation_test.mx raw

   1  package iskra
   2  
   3  import "testing"
   4  
   5  func TestBranchRotation(t *testing.T) {
   6  	if BranchRotation(BranchType, BranchFunc) != RotRight {
   7  		t.Fatal("Type->Func should be Right")
   8  	}
   9  	if BranchRotation(BranchFunc, BranchData) != RotRight {
  10  		t.Fatal("Func->Data should be Right")
  11  	}
  12  	if BranchRotation(BranchData, BranchType) != RotRight {
  13  		t.Fatal("Data->Type should be Right")
  14  	}
  15  	if BranchRotation(BranchFunc, BranchType) != RotLeft {
  16  		t.Fatal("Func->Type should be Left")
  17  	}
  18  	if BranchRotation(BranchType, BranchType) != RotStay {
  19  		t.Fatal("Type->Type should be Stay")
  20  	}
  21  }
  22  
  23  func TestBranchRotationInvalid(t *testing.T) {
  24  	if BranchRotation(0, BranchType) != RotUnknown {
  25  		t.Fatal("invalid from should be Unknown")
  26  	}
  27  	if BranchRotation(BranchType, 0) != RotUnknown {
  28  		t.Fatal("invalid to should be Unknown")
  29  	}
  30  }
  31  
  32  func TestRotationString(t *testing.T) {
  33  	if RotRight.String() != "right" {
  34  		t.Fatal("wrong string for RotRight")
  35  	}
  36  	if RotBlockOpen.String() != "{" {
  37  		t.Fatal("wrong string for RotBlockOpen")
  38  	}
  39  }
  40  
  41  func TestRotationIsStructural(t *testing.T) {
  42  	if RotRight.IsStructural() {
  43  		t.Fatal("RotRight should not be structural")
  44  	}
  45  	if !RotBlockOpen.IsStructural() {
  46  		t.Fatal("RotBlockOpen should be structural")
  47  	}
  48  	if !RotSeparator.IsStructural() {
  49  		t.Fatal("RotSeparator should be structural")
  50  	}
  51  }
  52  
  53  func TestRotationRoundtrip(t *testing.T) {
  54  	var m MetaEntry
  55  	m.SetRotation(RotLeft)
  56  	if m.GetRotation() != RotLeft {
  57  		t.Fatal("rotation round-trip failed")
  58  	}
  59  }
  60  
  61  func TestBigramTransition(t *testing.T) {
  62  	var m MetaEntry
  63  	path := MakeTritPath(BranchFunc, SubControl)
  64  	m.SetBigramTransition(RotRight, path)
  65  	rot, got := m.GetBigramTransition()
  66  	if rot != RotRight {
  67  		t.Fatal("wrong rotation")
  68  	}
  69  	if got != path {
  70  		t.Fatal("wrong target path")
  71  	}
  72  }
  73