@@ -167,7 +167,7 @@ func TestConvert(t *testing.T) {
167167// TestAll tests the All function.
168168func TestAll (t * testing.T ) {
169169 ParallelTasks (2 )
170- minLoadPeGoroutine = 20
170+ minLoadPerGoroutine = 20
171171 tests := []struct {
172172 name string
173173 in []Trit
@@ -218,7 +218,7 @@ func TestAll(t *testing.T) {
218218// TestAny tests the Any function.
219219func TestAny (t * testing.T ) {
220220 ParallelTasks (2 )
221- minLoadPeGoroutine = 20
221+ minLoadPerGoroutine = 20
222222 tests := []struct {
223223 name string
224224 in []Trit
@@ -988,7 +988,7 @@ func TestNeq(t *testing.T) {
988988// TestKnown tests the Known function.
989989func TestKnown (t * testing.T ) {
990990 ParallelTasks (2 )
991- minLoadPeGoroutine = 20
991+ minLoadPerGoroutine = 20
992992 tests := []struct {
993993 name string
994994 in []Trit
@@ -1107,7 +1107,7 @@ func TestRandom(t *testing.T) {
11071107 }
11081108
11091109 // Unknow - 0%
1110- for i := 0 ; i < 100 ; i ++ {
1110+ for i := 0 ; i < 10 ; i ++ {
11111111 result = Random (0 )
11121112 if result == Unknown {
11131113 t .Errorf ("Expected a random value as True or False, got %v" ,
@@ -1116,10 +1116,58 @@ func TestRandom(t *testing.T) {
11161116 }
11171117
11181118 // Two arguments.
1119- for i := 0 ; i < 100 ; i ++ {
1119+ for i := 0 ; i < 10 ; i ++ {
11201120 result = Random (90 , 5 , 5 )
11211121 if result != Unknown {
11221122 t .Errorf ("Expected a random value as Unknown, got %v" , result )
11231123 }
11241124 }
1125+
1126+ result = Random (90 , 60 , 90 )
1127+ if result != Unknown {
1128+ t .Errorf ("Expected a random value as Unknown, got %v" , result )
1129+ }
1130+ }
1131+
1132+ // TestConsensus tests Consensus function.
1133+ func TestConsensus (t * testing.T ) {
1134+ testCases := []struct {
1135+ name string
1136+ input []Trit
1137+ expected Trit
1138+ }{
1139+ {"All True" , []Trit {True , True , True }, True },
1140+ {"All False" , []Trit {False , False , False }, False },
1141+ {"Mixed" , []Trit {True , False , True }, Unknown },
1142+ {"With Unknown" , []Trit {True , True , Unknown }, Unknown },
1143+ }
1144+
1145+ for _ , tc := range testCases {
1146+ t .Run (tc .name , func (t * testing.T ) {
1147+ if result := Consensus (tc .input ... ); result != tc .expected {
1148+ t .Fatalf ("Expected %v, but got %v" , tc .expected , result )
1149+ }
1150+ })
1151+ }
1152+ }
1153+
1154+ // TestMajority tests Majority function.
1155+ func TestMajority (t * testing.T ) {
1156+ testCases := []struct {
1157+ name string
1158+ input []Trit
1159+ expected Trit
1160+ }{
1161+ {"Majority True" , []Trit {True , True , False }, True },
1162+ {"Majority False" , []Trit {False , False , True }, False },
1163+ {"No Majority" , []Trit {True , False , Unknown }, Unknown },
1164+ }
1165+
1166+ for _ , tc := range testCases {
1167+ t .Run (tc .name , func (t * testing.T ) {
1168+ if result := Majority (tc .input ... ); result != tc .expected {
1169+ t .Fatalf ("Expected %v, but got %v" , tc .expected , result )
1170+ }
1171+ })
1172+ }
11251173}
0 commit comments