From 065d32e7f0b77a2d48364aa25b3ffcc81c857f8b Mon Sep 17 00:00:00 2001 From: goloop Date: Sat, 1 Jul 2023 16:41:42 +0300 Subject: [PATCH] Add Random function --- fn.go | 47 +++++ fn_test.go | 199 ++++++++++++++---- trit_test.go | 576 ++++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 662 insertions(+), 160 deletions(-) diff --git a/fn.go b/fn.go index 7cf5e5f..1887919 100644 --- a/fn.go +++ b/fn.go @@ -2,9 +2,11 @@ package trit import ( "context" + "math/rand" "reflect" "runtime" "sync" + "time" ) var ( @@ -617,3 +619,48 @@ func IsConfidence[T Logicable](ts ...T) bool { return true } + +// Random returns a random Trit value. +// The function can accept an optional argument that indicates the +// percentage probability of the occurrence of the Unknown event. +// +// Example usage: +// +// a := trit.Random() +// fmt.Println(a.String()) // Output: True, False or Unknown +// +// b := trit.Random(0) +// fmt.Println(b.String()) // Output: True or False +// +// c := trit.Random(50) +// fmt.Println(c.String()) // Output: With a probability of 50% is Unknown +func Random(up ...uint8) Trit { + // Determination of the probability of occurrence of the event Unknown. + var p int + + if len(up) == 0 { + p = 33 + } else { + for _, v := range up { + p += int(v) + } + } + + if p > 100 { + p = 100 + } + + // Generate random value. + rand.Seed(time.Now().UnixNano()) + value := rand.Intn(100) + + if value < p { + return Unknown + } + + if value < (100-p)/2 { + return True + } + + return False +} diff --git a/fn_test.go b/fn_test.go index 3323f3a..00da451 100644 --- a/fn_test.go +++ b/fn_test.go @@ -556,7 +556,10 @@ func TestAnd(t *testing.T) { {"Should be False for (False, Unknown)", False, Unknown, False}, {"Should be False for (False, True)", False, True, False}, {"Should be False for (Unknown, False)", Unknown, False, False}, - {"Should be Unknown for (Unknown, Unknown)", Unknown, Unknown, Unknown}, + { + "Should be Unknown for (Unknown, Unknown)", + Unknown, Unknown, Unknown, + }, {"Should be Unknown for (Unknown, True)", Unknown, True, Unknown}, {"Should be False for (True, False)", True, False, False}, {"Should be Unknown for (True, Unknown)", True, Unknown, Unknown}, @@ -567,7 +570,8 @@ func TestAnd(t *testing.T) { t.Run(test.name, func(t *testing.T) { result := And(test.a, test.b) if result != test.out { - t.Errorf("And did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("And did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -585,7 +589,10 @@ func TestOr(t *testing.T) { {"Should be Unknown for (False, Unknown)", False, Unknown, Unknown}, {"Should be True for (False, True)", False, True, True}, {"Should be Unknown for (Unknown, False)", Unknown, False, Unknown}, - {"Should be Unknown for (Unknown, Unknown)", Unknown, Unknown, Unknown}, + { + "Should be Unknown for (Unknown, Unknown)", + Unknown, Unknown, Unknown, + }, {"Should be True for (Unknown, True)", Unknown, True, True}, {"Should be True for (True, False)", True, False, True}, {"Should be True for (True, Unknown)", True, Unknown, True}, @@ -596,7 +603,8 @@ func TestOr(t *testing.T) { t.Run(test.name, func(t *testing.T) { result := Or(test.a, test.b) if result != test.out { - t.Errorf("Or did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Or did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -614,7 +622,10 @@ func TestXor(t *testing.T) { {"Should be Unknown for (False, Unknown)", False, Unknown, Unknown}, {"Should be True for (False, True)", False, True, True}, {"Should be Unknown for (Unknown, False)", Unknown, False, Unknown}, - {"Should be Unknown for (Unknown, Unknown)", Unknown, Unknown, Unknown}, + { + "Should be Unknown for (Unknown, Unknown)", + Unknown, Unknown, Unknown, + }, {"Should be Unknown for (Unknown, True)", Unknown, True, Unknown}, {"Should be True for (True, False)", True, False, True}, {"Should be Unknown for (True, Unknown)", True, Unknown, Unknown}, @@ -625,7 +636,8 @@ func TestXor(t *testing.T) { t.Run(test.name, func(t *testing.T) { result := Xor(test.a, test.b) if result != test.out { - t.Errorf("Xor did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Xor did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -643,7 +655,10 @@ func TestNand(t *testing.T) { {"Should be True for (False, Unknown)", False, Unknown, True}, {"Should be True for (False, True)", False, True, True}, {"Should be True for (Unknown, False)", Unknown, False, True}, - {"Should be Unknown for (Unknown, Unknown)", Unknown, Unknown, Unknown}, + { + "Should be Unknown for (Unknown, Unknown)", + Unknown, Unknown, Unknown, + }, {"Should be Unknown for (Unknown, True)", Unknown, True, Unknown}, {"Should be True for (True, False)", True, False, True}, {"Should be Unknown for (True, Unknown)", True, Unknown, Unknown}, @@ -654,7 +669,8 @@ func TestNand(t *testing.T) { t.Run(test.name, func(t *testing.T) { result := Nand(test.a, test.b) if result != test.out { - t.Errorf("Nand did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Nand did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -672,7 +688,10 @@ func TestNor(t *testing.T) { {"Should be Unknown for (False, Unknown)", False, Unknown, Unknown}, {"Should be False for (False, True)", False, True, False}, {"Should be Unknown for (Unknown, False)", Unknown, False, Unknown}, - {"Should be Unknown for (Unknown, Unknown)", Unknown, Unknown, Unknown}, + { + "Should be Unknown for (Unknown, Unknown)", + Unknown, Unknown, Unknown, + }, {"Should be False for (Unknown, True)", Unknown, True, False}, {"Should be False for (True, False)", True, False, False}, {"Should be False for (True, Unknown)", True, Unknown, False}, @@ -683,7 +702,8 @@ func TestNor(t *testing.T) { t.Run(test.name, func(t *testing.T) { result := Nor(test.a, test.b) if result != test.out { - t.Errorf("Nor did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Nor did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -701,7 +721,10 @@ func TestNxor(t *testing.T) { {"Should be Unknown for (False, Unknown)", False, Unknown, Unknown}, {"Should be False for (False, True)", False, True, False}, {"Should be Unknown for (Unknown, False)", Unknown, False, Unknown}, - {"Should be Unknown for (Unknown, Unknown)", Unknown, Unknown, Unknown}, + { + "Should be Unknown for (Unknown, Unknown)", + Unknown, Unknown, Unknown, + }, {"Should be Unknown for (Unknown, True)", Unknown, True, Unknown}, {"Should be False for (True, False)", True, False, False}, {"Should be Unknown for (True, Unknown)", True, Unknown, Unknown}, @@ -712,7 +735,8 @@ func TestNxor(t *testing.T) { t.Run(test.name, func(t *testing.T) { result := Nxor(test.a, test.b) if result != test.out { - t.Errorf("Nxor did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Nxor did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -730,7 +754,10 @@ func TestMin(t *testing.T) { {"Should be False for (False, Unknown)", False, Unknown, False}, {"Should be False for (False, True)", False, True, False}, {"Should be False for (Unknown, False)", Unknown, False, False}, - {"Should be Unknown for (Unknown, Unknown)", Unknown, Unknown, Unknown}, + { + "Should be Unknown for (Unknown, Unknown)", + Unknown, Unknown, Unknown, + }, {"Should be Unknown for (Unknown, True)", Unknown, True, Unknown}, {"Should be False for (True, False)", True, False, False}, {"Should be Unknown for (True, Unknown)", True, Unknown, Unknown}, @@ -741,7 +768,8 @@ func TestMin(t *testing.T) { t.Run(test.name, func(t *testing.T) { result := Min(test.a, test.b) if result != test.out { - t.Errorf("Min did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Min did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -759,7 +787,10 @@ func TestMax(t *testing.T) { {"Should be Unknown for (False, Unknown)", False, Unknown, Unknown}, {"Should be True for (False, True)", False, True, True}, {"Should be Unknown for (Unknown, False)", Unknown, False, Unknown}, - {"Should be Unknown for (Unknown, Unknown)", Unknown, Unknown, Unknown}, + { + "Should be Unknown for (Unknown, Unknown)", + Unknown, Unknown, Unknown, + }, {"Should be True for (Unknown, True)", Unknown, True, True}, {"Should be True for (True, False)", True, False, True}, {"Should be True for (True, Unknown)", True, Unknown, True}, @@ -770,7 +801,8 @@ func TestMax(t *testing.T) { t.Run(test.name, func(t *testing.T) { result := Max(test.a, test.b) if result != test.out { - t.Errorf("Max did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Max did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -799,7 +831,8 @@ func TestImp(t *testing.T) { t.Run(test.name, func(t *testing.T) { result := Imp(test.a, test.b) if result != test.out { - t.Errorf("Imp did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Imp did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -813,22 +846,50 @@ func TestNimp(t *testing.T) { b Trit out Trit }{ - {"Nimp should return False for (False, False)", False, False, False}, - {"Nimp should return False for (False, Unknown)", False, Unknown, False}, - {"Nimp should return False for (False, True)", False, True, False}, - {"Nimp should return Unknown for (Unknown, False)", Unknown, False, Unknown}, - {"Nimp should return False for (Unknown, Unknown)", Unknown, Unknown, False}, - {"Nimp should return False for (Unknown, True)", Unknown, True, False}, - {"Nimp should return True for (True, False)", True, False, True}, - {"Nimp should return Unknown for (True, Unknown)", True, Unknown, Unknown}, - {"Nimp should return False for (True, True)", True, True, False}, + { + "Nimp should return False for (False, False)", + False, False, False, + }, + { + "Nimp should return False for (False, Unknown)", + False, Unknown, False, + }, + { + "Nimp should return False for (False, True)", + False, True, False, + }, + { + "Nimp should return Unknown for (Unknown, False)", + Unknown, False, Unknown, + }, + { + "Nimp should return False for (Unknown, Unknown)", + Unknown, Unknown, False, + }, + { + "Nimp should return False for (Unknown, True)", + Unknown, True, False, + }, + { + "Nimp should return True for (True, False)", + True, False, True, + }, + { + "Nimp should return Unknown for (True, Unknown)", + True, Unknown, Unknown, + }, + { + "Nimp should return False for (True, True)", + True, True, False, + }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { result := Nimp(test.a, test.b) if result != test.out { - t.Errorf("Nimp did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Nimp did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -843,13 +904,28 @@ func TestEq(t *testing.T) { out Trit }{ {"Eq should return True for (False, False)", False, False, True}, - {"Eq should return Unknown for (False, Unknown)", False, Unknown, Unknown}, + { + "Eq should return Unknown for (False, Unknown)", + False, Unknown, Unknown, + }, {"Eq should return False for (False, True)", False, True, False}, - {"Eq should return Unknown for (Unknown, False)", Unknown, False, Unknown}, - {"Eq should return Unknown for (Unknown, Unknown)", Unknown, Unknown, Unknown}, - {"Eq should return Unknown for (Unknown, True)", Unknown, True, Unknown}, + { + "Eq should return Unknown for (Unknown, False)", + Unknown, False, Unknown, + }, + { + "Eq should return Unknown for (Unknown, Unknown)", + Unknown, Unknown, Unknown, + }, + { + "Eq should return Unknown for (Unknown, True)", + Unknown, True, Unknown, + }, {"Eq should return False for (True, False)", True, False, False}, - {"Eq should return Unknown for (True, Unknown)", True, Unknown, Unknown}, + { + "Eq should return Unknown for (True, Unknown)", + True, Unknown, Unknown, + }, {"Eq should return True for (True, True)", True, True, True}, } @@ -857,7 +933,8 @@ func TestEq(t *testing.T) { t.Run(test.name, func(t *testing.T) { result := Eq(test.a, test.b) if result != test.out { - t.Errorf("Eq did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Eq did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -872,13 +949,28 @@ func TestNeq(t *testing.T) { out Trit }{ {"Neq should return False for (False, False)", False, False, False}, - {"Neq should return Unknown for (False, Unknown)", False, Unknown, Unknown}, + { + "Neq should return Unknown for (False, Unknown)", + False, Unknown, Unknown, + }, {"Neq should return True for (False, True)", False, True, True}, - {"Neq should return Unknown for (Unknown, False)", Unknown, False, Unknown}, - {"Neq should return Unknown for (Unknown, Unknown)", Unknown, Unknown, Unknown}, - {"Neq should return Unknown for (Unknown, True)", Unknown, True, Unknown}, + { + "Neq should return Unknown for (Unknown, False)", + Unknown, False, Unknown, + }, + { + "Neq should return Unknown for (Unknown, Unknown)", + Unknown, Unknown, Unknown, + }, + { + "Neq should return Unknown for (Unknown, True)", + Unknown, True, Unknown, + }, {"Neq should return True for (True, False)", True, False, True}, - {"Neq should return Unknown for (True, Unknown)", True, Unknown, Unknown}, + { + "Neq should return Unknown for (True, Unknown)", + True, Unknown, Unknown, + }, {"Neq should return False for (True, True)", True, True, False}, } @@ -886,7 +978,8 @@ func TestNeq(t *testing.T) { t.Run(test.name, func(t *testing.T) { result := Neq(test.a, test.b) if result != test.out { - t.Errorf("Neq did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Neq did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -983,7 +1076,7 @@ func TestIsConfidence(t *testing.T) { out: true, }, { - name: "IsConfidence should return false for (False, Unknown, True)", + name: "IsConfidence should return false (False, Unknown, True)", in: []Trit{False, Unknown, True}, out: false, }, @@ -1004,3 +1097,29 @@ func TestIsConfidence(t *testing.T) { }) } } + +// TestRandom tests the Random function. +func TestRandom(t *testing.T) { + // No arguments. + result := Random() + if !(result == False || result == True || result == Unknown) { + t.Errorf("Something went wrong with Random()") + } + + // Unknow - 0% + for i := 0; i < 100; i++ { + result = Random(0) + if result == Unknown { + t.Errorf("Expected a random value as True or False, got %v", + result) + } + } + + // Two arguments. + for i := 0; i < 100; i++ { + result = Random(90, 5, 5) + if result != Unknown { + t.Errorf("Expected a random value as Unknown, got %v", result) + } + } +} diff --git a/trit_test.go b/trit_test.go index a485762..55db37f 100644 --- a/trit_test.go +++ b/trit_test.go @@ -404,22 +404,50 @@ func TestMethodAnd(t *testing.T) { b Trit out Trit }{ - {"And should return False for (False, False)", False, False, False}, - {"And should return False for (False, Unknown)", False, Unknown, False}, - {"And should return False for (False, True)", False, True, False}, - {"And should return False for (Unknown, False)", Unknown, False, False}, - {"And should return Unknown for (Unknown, Unknown)", Unknown, Unknown, Unknown}, - {"And should return Unknown for (Unknown, True)", Unknown, True, Unknown}, - {"And should return False for (True, False)", True, False, False}, - {"And should return Unknown for (True, Unknown)", True, Unknown, Unknown}, - {"And should return True for (True, True)", True, True, True}, + { + "And should return False for (False, False)", + False, False, False, + }, + { + "And should return False for (False, Unknown)", + False, Unknown, False, + }, + { + "And should return False for (False, True)", + False, True, False, + }, + { + "And should return False for (Unknown, False)", + Unknown, False, False, + }, + { + "And should return Unknown for (Unknown, Unknown)", + Unknown, Unknown, Unknown, + }, + { + "And should return Unknown for (Unknown, True)", + Unknown, True, Unknown, + }, + { + "And should return False for (True, False)", + True, False, False, + }, + { + "And should return Unknown for (True, Unknown)", + True, Unknown, Unknown, + }, + { + "And should return True for (True, True)", + True, True, True, + }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { result := test.a.And(test.b) if result != test.out { - t.Errorf("And did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("And did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -433,22 +461,50 @@ func TestMethodOr(t *testing.T) { b Trit out Trit }{ - {"Or should return False for (False, False)", False, False, False}, - {"Or should return Unknown for (False, Unknown)", False, Unknown, Unknown}, - {"Or should return True for (False, True)", False, True, True}, - {"Or should return Unknown for (Unknown, False)", Unknown, False, Unknown}, - {"Or should return Unknown for (Unknown, Unknown)", Unknown, Unknown, Unknown}, - {"Or should return True for (Unknown, True)", Unknown, True, True}, - {"Or should return True for (True, False)", True, False, True}, - {"Or should return True for (True, Unknown)", True, Unknown, True}, - {"Or should return True for (True, True)", True, True, True}, + { + "Or should return False for (False, False)", + False, False, False, + }, + { + "Or should return Unknown for (False, Unknown)", + False, Unknown, Unknown, + }, + { + "Or should return True for (False, True)", + False, True, True, + }, + { + "Or should return Unknown for (Unknown, False)", + Unknown, False, Unknown, + }, + { + "Or should return Unknown for (Unknown, Unknown)", + Unknown, Unknown, Unknown, + }, + { + "Or should return True for (Unknown, True)", + Unknown, True, True, + }, + { + "Or should return True for (True, False)", + True, False, True, + }, + { + "Or should return True for (True, Unknown)", + True, Unknown, True, + }, + { + "Or should return True for (True, True)", + True, True, True, + }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { result := test.a.Or(test.b) if result != test.out { - t.Errorf("Or did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Or did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -462,22 +518,50 @@ func TestMethodXor(t *testing.T) { b Trit out Trit }{ - {"Xor should return False for (False, False)", False, False, False}, - {"Xor should return Unknown for (False, Unknown)", False, Unknown, Unknown}, - {"Xor should return True for (False, True)", False, True, True}, - {"Xor should return Unknown for (Unknown, False)", Unknown, False, Unknown}, - {"Xor should return Unknown for (Unknown, Unknown)", Unknown, Unknown, Unknown}, - {"Xor should return Unknown for (Unknown, True)", Unknown, True, Unknown}, - {"Xor should return True for (True, False)", True, False, True}, - {"Xor should return Unknown for (True, Unknown)", True, Unknown, Unknown}, - {"Xor should return False for (True, True)", True, True, False}, + { + "Xor should return False for (False, False)", + False, False, False, + }, + { + "Xor should return Unknown for (False, Unknown)", + False, Unknown, Unknown, + }, + { + "Xor should return True for (False, True)", + False, True, True, + }, + { + "Xor should return Unknown for (Unknown, False)", + Unknown, False, Unknown, + }, + { + "Xor should return Unknown for (Unknown, Unknown)", + Unknown, Unknown, Unknown, + }, + { + "Xor should return Unknown for (Unknown, True)", + Unknown, True, Unknown, + }, + { + "Xor should return True for (True, False)", + True, False, True, + }, + { + "Xor should return Unknown for (True, Unknown)", + True, Unknown, Unknown, + }, + { + "Xor should return False for (True, True)", + True, True, False, + }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { result := test.a.Xor(test.b) if result != test.out { - t.Errorf("Xor did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Xor did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -491,22 +575,50 @@ func TestMethodNand(t *testing.T) { b Trit out Trit }{ - {"Nand should return True for (False, False)", False, False, True}, - {"Nand should return True for (False, Unknown)", False, Unknown, True}, - {"Nand should return True for (False, True)", False, True, True}, - {"Nand should return True for (Unknown, False)", Unknown, False, True}, - {"Nand should return Unknown for (Unknown, Unknown)", Unknown, Unknown, Unknown}, - {"Nand should return Unknown for (Unknown, True)", Unknown, True, Unknown}, - {"Nand should return True for (True, False)", True, False, True}, - {"Nand should return Unknown for (True, Unknown)", True, Unknown, Unknown}, - {"Nand should return False for (True, True)", True, True, False}, + { + "Nand should return True for (False, False)", + False, False, True, + }, + { + "Nand should return True for (False, Unknown)", + False, Unknown, True, + }, + { + "Nand should return True for (False, True)", + False, True, True, + }, + { + "Nand should return True for (Unknown, False)", + Unknown, False, True, + }, + { + "Nand should return Unknown for (Unknown, Unknown)", + Unknown, Unknown, Unknown, + }, + { + "Nand should return Unknown for (Unknown, True)", + Unknown, True, Unknown, + }, + { + "Nand should return True for (True, False)", + True, False, True, + }, + { + "Nand should return Unknown for (True, Unknown)", + True, Unknown, Unknown, + }, + { + "Nand should return False for (True, True)", + True, True, False, + }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { result := test.a.Nand(test.b) if result != test.out { - t.Errorf("Nand did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Nand did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -520,22 +632,50 @@ func TestMethodNor(t *testing.T) { b Trit out Trit }{ - {"Nor should return True for (False, False)", False, False, True}, - {"Nor should return Unknown for (False, Unknown)", False, Unknown, Unknown}, - {"Nor should return False for (False, True)", False, True, False}, - {"Nor should return Unknown for (Unknown, False)", Unknown, False, Unknown}, - {"Nor should return Unknown for (Unknown, Unknown)", Unknown, Unknown, Unknown}, - {"Nor should return False for (Unknown, True)", Unknown, True, False}, - {"Nor should return False for (True, False)", True, False, False}, - {"Nor should return False for (True, Unknown)", True, Unknown, False}, - {"Nor should return False for (True, True)", True, True, False}, + { + "Nor should return True for (False, False)", + False, False, True, + }, + { + "Nor should return Unknown for (False, Unknown)", + False, Unknown, Unknown, + }, + { + "Nor should return False for (False, True)", + False, True, False, + }, + { + "Nor should return Unknown for (Unknown, False)", + Unknown, False, Unknown, + }, + { + "Nor should return Unknown for (Unknown, Unknown)", + Unknown, Unknown, Unknown, + }, + { + "Nor should return False for (Unknown, True)", + Unknown, True, False, + }, + { + "Nor should return False for (True, False)", + True, False, False, + }, + { + "Nor should return False for (True, Unknown)", + True, Unknown, False, + }, + { + "Nor should return False for (True, True)", + True, True, False, + }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { result := test.a.Nor(test.b) if result != test.out { - t.Errorf("Nor did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Nor did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -549,22 +689,50 @@ func TestMethodNxor(t *testing.T) { b Trit out Trit }{ - {"Nxor should return True for (False, False)", False, False, True}, - {"Nxor should return Unknown for (False, Unknown)", False, Unknown, Unknown}, - {"Nxor should return False for (False, True)", False, True, False}, - {"Nxor should return Unknown for (Unknown, False)", Unknown, False, Unknown}, - {"Nxor should return Unknown for (Unknown, Unknown)", Unknown, Unknown, Unknown}, - {"Nxor should return Unknown for (Unknown, True)", Unknown, True, Unknown}, - {"Nxor should return False for (True, False)", True, False, False}, - {"Nxor should return Unknown for (True, Unknown)", True, Unknown, Unknown}, - {"Nxor should return True for (True, True)", True, True, True}, + { + "Nxor should return True for (False, False)", + False, False, True, + }, + { + "Nxor should return Unknown for (False, Unknown)", + False, Unknown, Unknown, + }, + { + "Nxor should return False for (False, True)", + False, True, False, + }, + { + "Nxor should return Unknown for (Unknown, False)", + Unknown, False, Unknown, + }, + { + "Nxor should return Unknown for (Unknown, Unknown)", + Unknown, Unknown, Unknown, + }, + { + "Nxor should return Unknown for (Unknown, True)", + Unknown, True, Unknown, + }, + { + "Nxor should return False for (True, False)", + True, False, False, + }, + { + "Nxor should return Unknown for (True, Unknown)", + True, Unknown, Unknown, + }, + { + "Nxor should return True for (True, True)", + True, True, True, + }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { result := test.a.Nxor(test.b) if result != test.out { - t.Errorf("Nxor did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Nxor did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -578,22 +746,50 @@ func TestMethodMin(t *testing.T) { b Trit out Trit }{ - {"Min should return False for (False, False)", False, False, False}, - {"Min should return False for (False, Unknown)", False, Unknown, False}, - {"Min should return False for (False, True)", False, True, False}, - {"Min should return False for (Unknown, False)", Unknown, False, False}, - {"Min should return Unknown for (Unknown, Unknown)", Unknown, Unknown, Unknown}, - {"Min should return Unknown for (Unknown, True)", Unknown, True, Unknown}, - {"Min should return False for (True, False)", True, False, False}, - {"Min should return Unknown for (True, Unknown)", True, Unknown, Unknown}, - {"Min should return True for (True, True)", True, True, True}, + { + "Min should return False for (False, False)", + False, False, False, + }, + { + "Min should return False for (False, Unknown)", + False, Unknown, False, + }, + { + "Min should return False for (False, True)", + False, True, False, + }, + { + "Min should return False for (Unknown, False)", + Unknown, False, False, + }, + { + "Min should return Unknown for (Unknown, Unknown)", + Unknown, Unknown, Unknown, + }, + { + "Min should return Unknown for (Unknown, True)", + Unknown, True, Unknown, + }, + { + "Min should return False for (True, False)", + True, False, False, + }, + { + "Min should return Unknown for (True, Unknown)", + True, Unknown, Unknown, + }, + { + "Min should return True for (True, True)", + True, True, True, + }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { result := test.a.Min(test.b) if result != test.out { - t.Errorf("Min did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Min did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -607,22 +803,50 @@ func TestMethodMax(t *testing.T) { b Trit out Trit }{ - {"Max should return False for (False, False)", False, False, False}, - {"Max should return Unknown for (False, Unknown)", False, Unknown, Unknown}, - {"Max should return True for (False, True)", False, True, True}, - {"Max should return Unknown for (Unknown, False)", Unknown, False, Unknown}, - {"Max should return Unknown for (Unknown, Unknown)", Unknown, Unknown, Unknown}, - {"Max should return True for (Unknown, True)", Unknown, True, True}, - {"Max should return True for (True, False)", True, False, True}, - {"Max should return True for (True, Unknown)", True, Unknown, True}, - {"Max should return True for (True, True)", True, True, True}, + { + "Max should return False for (False, False)", + False, False, False, + }, + { + "Max should return Unknown for (False, Unknown)", + False, Unknown, Unknown, + }, + { + "Max should return True for (False, True)", + False, True, True, + }, + { + "Max should return Unknown for (Unknown, False)", + Unknown, False, Unknown, + }, + { + "Max should return Unknown for (Unknown, Unknown)", + Unknown, Unknown, Unknown, + }, + { + "Max should return True for (Unknown, True)", + Unknown, True, True, + }, + { + "Max should return True for (True, False)", + True, False, True, + }, + { + "Max should return True for (True, Unknown)", + True, Unknown, True, + }, + { + "Max should return True for (True, True)", + True, True, True, + }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { result := test.a.Max(test.b) if result != test.out { - t.Errorf("Max did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Max did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -636,22 +860,50 @@ func TestMethodImp(t *testing.T) { b Trit out Trit }{ - {"Imp should return True for (False, False)", False, False, True}, - {"Imp should return True for (False, Unknown)", False, Unknown, True}, - {"Imp should return True for (False, True)", False, True, True}, - {"Imp should return Unknown for (Unknown, False)", Unknown, False, Unknown}, - {"Imp should return True for (Unknown, Unknown)", Unknown, Unknown, True}, - {"Imp should return True for (Unknown, True)", Unknown, True, True}, - {"Imp should return False for (True, False)", True, False, False}, - {"Imp should return Unknown for (True, Unknown)", True, Unknown, Unknown}, - {"Imp should return True for (True, True)", True, True, True}, + { + "Imp should return True for (False, False)", + False, False, True, + }, + { + "Imp should return True for (False, Unknown)", + False, Unknown, True, + }, + { + "Imp should return True for (False, True)", + False, True, True, + }, + { + "Imp should return Unknown for (Unknown, False)", + Unknown, False, Unknown, + }, + { + "Imp should return True for (Unknown, Unknown)", + Unknown, Unknown, True, + }, + { + "Imp should return True for (Unknown, True)", + Unknown, True, True, + }, + { + "Imp should return False for (True, False)", + True, False, False, + }, + { + "Imp should return Unknown for (True, Unknown)", + True, Unknown, Unknown, + }, + { + "Imp should return True for (True, True)", + True, True, True, + }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { result := test.a.Imp(test.b) if result != test.out { - t.Errorf("Imp did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Imp did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -665,22 +917,50 @@ func TestMethodNimp(t *testing.T) { b Trit out Trit }{ - {"Nimp should return False for (False, False)", False, False, False}, - {"Nimp should return False for (False, Unknown)", False, Unknown, False}, - {"Nimp should return False for (False, True)", False, True, False}, - {"Nimp should return Unknown for (Unknown, False)", Unknown, False, Unknown}, - {"Nimp should return False for (Unknown, Unknown)", Unknown, Unknown, False}, - {"Nimp should return False for (Unknown, True)", Unknown, True, False}, - {"Nimp should return True for (True, False)", True, False, True}, - {"Nimp should return Unknown for (True, Unknown)", True, Unknown, Unknown}, - {"Nimp should return False for (True, True)", True, True, False}, + { + "Nimp should return False for (False, False)", + False, False, False, + }, + { + "Nimp should return False for (False, Unknown)", + False, Unknown, False, + }, + { + "Nimp should return False for (False, True)", + False, True, False, + }, + { + "Nimp should return Unknown for (Unknown, False)", + Unknown, False, Unknown, + }, + { + "Nimp should return False for (Unknown, Unknown)", + Unknown, Unknown, False, + }, + { + "Nimp should return False for (Unknown, True)", + Unknown, True, False, + }, + { + "Nimp should return True for (True, False)", + True, False, True, + }, + { + "Nimp should return Unknown for (True, Unknown)", + True, Unknown, Unknown, + }, + { + "Nimp should return False for (True, True)", + True, True, False, + }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { result := test.a.Nimp(test.b) if result != test.out { - t.Errorf("Nimp did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Nimp did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -694,22 +974,50 @@ func TestMethodEq(t *testing.T) { b Trit out Trit }{ - {"Eq should return True for (False, False)", False, False, True}, - {"Eq should return Unknown for (False, Unknown)", False, Unknown, Unknown}, - {"Eq should return False for (False, True)", False, True, False}, - {"Eq should return Unknown for (Unknown, False)", Unknown, False, Unknown}, - {"Eq should return Unknown for (Unknown, Unknown)", Unknown, Unknown, Unknown}, - {"Eq should return Unknown for (Unknown, True)", Unknown, True, Unknown}, - {"Eq should return False for (True, False)", True, False, False}, - {"Eq should return Unknown for (True, Unknown)", True, Unknown, Unknown}, - {"Eq should return True for (True, True)", True, True, True}, + { + "Eq should return True for (False, False)", + False, False, True, + }, + { + "Eq should return Unknown for (False, Unknown)", + False, Unknown, Unknown, + }, + { + "Eq should return False for (False, True)", + False, True, False, + }, + { + "Eq should return Unknown for (Unknown, False)", + Unknown, False, Unknown, + }, + { + "Eq should return Unknown for (Unknown, Unknown)", + Unknown, Unknown, Unknown, + }, + { + "Eq should return Unknown for (Unknown, True)", + Unknown, True, Unknown, + }, + { + "Eq should return False for (True, False)", + True, False, False, + }, + { + "Eq should return Unknown for (True, Unknown)", + True, Unknown, Unknown, + }, + { + "Eq should return True for (True, True)", + True, True, True, + }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { result := test.a.Eq(test.b) if result != test.out { - t.Errorf("Eq did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Eq did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) } @@ -723,22 +1031,50 @@ func TestMethodNeq(t *testing.T) { b Trit out Trit }{ - {"Neq should return False for (False, False)", False, False, False}, - {"Neq should return Unknown for (False, Unknown)", False, Unknown, Unknown}, - {"Neq should return True for (False, True)", False, True, True}, - {"Neq should return Unknown for (Unknown, False)", Unknown, False, Unknown}, - {"Neq should return Unknown for (Unknown, Unknown)", Unknown, Unknown, Unknown}, - {"Neq should return Unknown for (Unknown, True)", Unknown, True, Unknown}, - {"Neq should return True for (True, False)", True, False, True}, - {"Neq should return Unknown for (True, Unknown)", True, Unknown, Unknown}, - {"Neq should return False for (True, True)", True, True, False}, + { + "Neq should return False for (False, False)", + False, False, False, + }, + { + "Neq should return Unknown for (False, Unknown)", + False, Unknown, Unknown, + }, + { + "Neq should return True for (False, True)", + False, True, True, + }, + { + "Neq should return Unknown for (Unknown, False)", + Unknown, False, Unknown, + }, + { + "Neq should return Unknown for (Unknown, Unknown)", + Unknown, Unknown, Unknown, + }, + { + "Neq should return Unknown for (Unknown, True)", + Unknown, True, Unknown, + }, + { + "Neq should return True for (True, False)", + True, False, True, + }, + { + "Neq should return Unknown for (True, Unknown)", + True, Unknown, Unknown, + }, + { + "Neq should return False for (True, True)", + True, True, False, + }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { result := test.a.Neq(test.b) if result != test.out { - t.Errorf("Neq did not return %v for (%v, %v)", test.out, test.a, test.b) + t.Errorf("Neq did not return %v for (%v, %v)", + test.out, test.a, test.b) } }) }