-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfn_test.go
1197 lines (1115 loc) · 30.1 KB
/
fn_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package trit
import (
"reflect"
"testing"
)
// TestParalellTasks tests the ParallelTasks function.
func TestParallelTasks(t *testing.T) {
tests := []struct {
name string
inputs []int
want int
}{
{
name: "No input values",
inputs: []int{},
want: parallelTasks, // should return current value of pt
},
{
name: "Input values sum to less than 0",
inputs: []int{-10, -5},
want: 1, // should be set to 1
},
{
name: "Input values sum to 0",
inputs: []int{-5, 5},
want: 1, // should be set to 1
},
{
name: "Input values sum to more than maxParallelTasks",
inputs: []int{10, maxParallelTasks + 1},
want: maxParallelTasks, // should be set to maxParallelTasks
},
{
name: "Input values sum to valid value",
inputs: []int{3, 4},
want: 7, // should be set to the sum of the inputs
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := ParallelTasks(test.inputs...)
if got != test.want {
t.Errorf("ParallelTasks() = %v, want %v", got, test.want)
}
})
}
}
// TestIsFalse tests the IsFalse function.
func TestIsFalse(t *testing.T) {
tests := []struct {
name string
in int
out bool
}{
{"-1 should return true", -1, true},
{"1 should return false", 1, false},
{"0 should return false", 0, false},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := IsFalse(test.in)
if result != test.out {
t.Errorf("isFalse did not return %v for %v",
test.out, test.in)
}
})
}
}
// TestIsUnknown tests the IsUnknown function.
func TestIsUnknown(t *testing.T) {
tests := []struct {
name string
in int
out bool
}{
{"-1 should return false", -1, false},
{"1 should return false", 1, false},
{"0 should return true", 0, true},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := IsUnknown(test.in)
if result != test.out {
t.Errorf("IsUnknown did not return %v for %v",
test.out, test.in)
}
})
}
}
// TestIsTrue tests the IsTrue function.
func TestIsTrue(t *testing.T) {
tests := []struct {
name string
in int
out bool
}{
{"-1 should return false", -1, false},
{"1 should return true", 1, true},
{"0 should return false", 0, false},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := IsTrue(test.in)
if result != test.out {
t.Errorf("isTrue did not return %v for %v",
test.out, test.in)
}
})
}
}
// TestSet tests the Set function.
func TestSet(t *testing.T) {
tests := []struct {
name string
in int
out Trit
}{
{"-1 should return False", -1, False},
{"1 should return True", 1, True},
{"0 should return Unknown", 0, Unknown},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
var trit Trit
result := Set(&trit, test.in)
if result != test.out {
t.Errorf("Set did not return %v for %v",
test.out, test.in)
}
})
}
}
// TestDefine tests the Define function.
func TestDefine(t *testing.T) {
tests := []struct {
name string
in float64
out Trit
}{
{"-0.1 should return False", -0.1, False},
{"7.7 should return True", 7.7, True},
{"0.0 should return Unknown", 0.0, Unknown},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := Define(test.in)
if result != test.out {
t.Errorf("Define did not return %v for %v",
test.out, test.in)
}
})
}
}
// TestConvert tests the Convert function.
func TestConvert(t *testing.T) {
tests := []struct {
name string
in []int
out []Trit
}{
{"-0.1 should return False", []int{-1, 1}, []Trit{False, True}},
{"7.7 should return True", []int{0, 1}, []Trit{Unknown, True}},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := Convert(test.in...)
// DeepEqual is used to compare slices.
if !reflect.DeepEqual(result, test.out) {
t.Errorf("Convert did not return %v for %v",
test.out, test.in)
}
})
}
}
// TestAll tests the All function.
func TestAll(t *testing.T) {
ParallelTasks(2)
minLoadPerGoroutine = 20
tests := []struct {
name string
in []Trit
out Trit
}{
{"[1, 1, 1] should return True", []Trit{True, True, True}, True},
{"[1, 0, 1] should return False", []Trit{True, False, True}, False},
{"[0, 0, 0] should return False", []Trit{False, False, False}, False},
{"[0, 0, 1] should return False", []Trit{False, False, True}, False},
{"[0, 1, 0] should return False", []Trit{False, True, False}, False},
{"[0, 1, 1] should return False", []Trit{False, True, True}, False},
{"[1, 0, 0] should return False", []Trit{True, False, False}, False},
{"[1, 1, 0] should return False", []Trit{True, True, False}, False},
{
name: "Just empty list",
in: []Trit{},
out: False,
},
{
name: "A very large list for testing goroutines",
in: []Trit{
True, True, True, True, True, True, True, True, True, True,
True, True, True, True, True, True, True, True, True, True,
True, True, True, True, True, True, True, True, True, True,
True, True, True, True, True, True, True, True, True, True,
True, True, True, True, True, True, True, True, True, True,
True, True, True, True, True, True, True, True, True, True,
True, True, True, True, True, True, True, True, True, True,
True, True, True, Unknown, True, True, True, True, True, True,
True, True, True, True, True, True, True, True, True, True,
True, True, True, True, True, True, True, True, True, True,
},
out: False,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := All(test.in...)
if result != test.out {
t.Errorf("All did not return %v for %v",
test.out, test.in)
}
})
}
}
// TestAny tests the Any function.
func TestAny(t *testing.T) {
ParallelTasks(2)
minLoadPerGoroutine = 20
tests := []struct {
name string
in []Trit
out Trit
}{
{"[1, 1, 1] should return True", []Trit{True, True, True}, True},
{"[1, 0, 1] should return True", []Trit{True, False, True}, True},
{"[0, 0, 0] should return False", []Trit{False, False, False}, False},
{"[0, 0, 1] should return True", []Trit{False, False, True}, True},
{"[0, 1, 0] should return True", []Trit{False, True, False}, True},
{"[0, 1, 1] should return True", []Trit{False, True, True}, True},
{"[1, 0, 0] should return True", []Trit{True, False, False}, True},
{"[1, 1, 0] should return True", []Trit{True, True, False}, True},
{
name: "Just empty list",
in: []Trit{},
out: False,
},
{
name: "A very large list for testing goroutines",
in: []Trit{
False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, True, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False,
},
out: True,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := Any(test.in...)
if result != test.out {
t.Errorf("Any did not return %v for %v",
test.out, test.in)
}
})
}
}
// TestNone tests the None function.
func TestNone(t *testing.T) {
tests := []struct {
name string
in []Trit
out Trit
}{
{"[1, 1, 1] should return False", []Trit{True, True, True}, False},
{"[1, 0, 1] should return False", []Trit{True, False, True}, False},
{"[0, 0, 0] should return True", []Trit{False, False, False}, True},
{"[0, 0, 1] should return False", []Trit{False, False, True}, False},
{"[0, 1, 0] should return False", []Trit{False, True, False}, False},
{"[0, 1, 1] should return False", []Trit{False, True, True}, False},
{"[1, 0, 0] should return False", []Trit{True, False, False}, False},
{"[1, 1, 0] should return False", []Trit{True, True, False}, False},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := None(test.in...)
if result != test.out {
t.Errorf("None did not return %v for %v",
test.out, test.in)
}
})
}
}
// TestLogicToTrit tests the logicToTrit function.
func TestLogicToTrit(t *testing.T) {
// Numbers.
testsInt := []struct {
name string
in int
out Trit
}{
{"1 should return True", 1, True},
{"-1 should return False", -1, False},
{"0 should return Unknown", 0, Unknown},
{"-77 should return False", -77, False},
{"1000000 should return True", 1000000, True},
}
for _, test := range testsInt {
t.Run(test.name, func(t *testing.T) {
result := logicToTrit(test.in)
if result != test.out {
t.Errorf("logicToTrit did not return %v for %v",
test.out, test.in)
}
})
}
testsUint := []struct {
name string
in uint
out Trit
}{
{"1 should return True", 1, True},
{"0 should return Unknown", 0, Unknown},
{"1000000 should return True", 1000000, True},
}
for _, test := range testsUint {
t.Run(test.name, func(t *testing.T) {
result := logicToTrit(test.in)
if result != test.out {
t.Errorf("logicToTrit did not return %v for %v",
test.out, test.in)
}
})
}
testsFloat := []struct {
name string
in float64
out Trit
}{
{"0.3 should return True", 0.3, True},
{"-0.3 should return False", -0.3, False},
{"0.0 should return Unknown", 0.0, Unknown},
{"-77.5 should return False", -77.5, False},
{"1000000.5 should return True", 1000000.5, True},
}
for _, test := range testsFloat {
t.Run(test.name, func(t *testing.T) {
result := logicToTrit(test.in)
if result != test.out {
t.Errorf("logicToTrit did not return %v for %v",
test.out, test.in)
}
})
}
// Bool.
testsBool := []struct {
name string
in bool
out Trit
}{
{"trut should return True", true, True},
{"false should return False", false, False},
}
for _, test := range testsBool {
t.Run(test.name, func(t *testing.T) {
result := logicToTrit(test.in)
if result != test.out {
t.Errorf("logicToTrit did not return %v for %v",
test.out, test.in)
}
})
}
// Trit.
testsTrit := []struct {
name string
in Trit
out Trit
}{
{"True should return True", True, True},
{"False should return False", False, False},
{"Unknown should return False", Unknown, Unknown},
}
for _, test := range testsTrit {
t.Run(test.name, func(t *testing.T) {
result := logicToTrit(test.in)
if result != test.out {
t.Errorf("logicToTrit did not return %v for %v",
test.out, test.in)
}
})
}
}
// TestDefault tests the Default method.
func TestDefault(t *testing.T) {
t.Run("Default with bool value", func(t *testing.T) {
t1 := Unknown
Default(&t1, true)
if t1 != True {
t.Errorf("Default did not update Unknown to True")
}
t2 := Unknown
Default(&t2, false)
if t2 != False {
t.Errorf("Default did not update Unknown to False")
}
})
t.Run("Default with numeric value", func(t *testing.T) {
t1 := Unknown
Default(&t1, int32(1)) // for example int32
if t1 != True {
t.Errorf("Default did not update Unknown to True")
}
t2 := Unknown
Default(&t2, int64(-1)) // for example int64
if t2 != False {
t.Errorf("Default did not update Unknown to False")
}
})
t.Run("Default with Trit value", func(t *testing.T) {
t1 := Unknown
Default(&t1, True)
if t1 != True {
t.Errorf("Default did not update Unknown to True")
}
t2 := Unknown
Default(&t2, False)
if t2 != False {
t.Errorf("Default did not update Unknown to False")
}
})
t.Run("Should not update non-Unknown Trit", func(t *testing.T) {
t1 := True
Default(&t1, false)
if t1 != True {
t.Errorf("Default updated non-Unknown Trit")
}
})
}
// TestNot tests the Not function.
func TestNot(t *testing.T) {
tests := []struct {
name string
in Trit
out Trit
}{
{"Not should return True for False", False, True},
{"Not should return Unknown for Unknown", Unknown, Unknown},
{"Not should return False for True", True, False},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := Not(test.in)
if result != test.out {
t.Errorf("Not did not return %v for %v", test.out, test.in)
}
})
}
}
// TestMa tests the Ma function.
func TestMa(t *testing.T) {
tests := []struct {
name string
in Trit
out Trit
}{
{"Ma should return False for False", False, False},
{"Ma should return True for Unknown", Unknown, True},
{"Ma should return True for True", True, True},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := Ma(test.in)
if result != test.out {
t.Errorf("Ma did not return %v for %v", test.out, test.in)
}
})
}
}
// TestLa tests the La function.
func TestLa(t *testing.T) {
tests := []struct {
name string
in Trit
out Trit
}{
{"La should return False for False", False, False},
{"La should return False for Unknown", Unknown, False},
{"La should return True for True", True, True},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := La(test.in)
if result != test.out {
t.Errorf("La did not return %v for %v", test.out, test.in)
}
})
}
}
// TestIa tests the Ia function.
func TestIa(t *testing.T) {
tests := []struct {
name string
in Trit
out Trit
}{
{"Ia should return False for False", False, False},
{"Ia should return True for Unknown", Unknown, True},
{"Ia should return False for True", True, False},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := Ia(test.in)
if result != test.out {
t.Errorf("Ia did not return %v for %v", test.out, test.in)
}
})
}
}
// TestAnd tests the And function.
func TestAnd(t *testing.T) {
tests := []struct {
name string
a Trit
b Trit
out Trit
}{
{"Should be False for (False, False)", False, False, False},
{"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, True)", Unknown, True, Unknown},
{"Should be False for (True, False)", True, False, False},
{"Should be Unknown for (True, Unknown)", True, Unknown, Unknown},
{"Should be True for (True, True)", True, True, True},
}
for _, test := range tests {
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)
}
})
}
}
// TestOr tests the Or function.
func TestOr(t *testing.T) {
tests := []struct {
name string
a Trit
b Trit
out Trit
}{
{"Should be False for (False, False)", False, False, False},
{"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 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},
{"Should be True for (True, True)", True, True, True},
}
for _, test := range tests {
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)
}
})
}
}
// TestXor tests the Xor function.
func TestXor(t *testing.T) {
tests := []struct {
name string
a Trit
b Trit
out Trit
}{
{"Should be False for (False, False)", False, False, False},
{"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, True)", Unknown, True, Unknown},
{"Should be True for (True, False)", True, False, True},
{"Should be Unknown for (True, Unknown)", True, Unknown, Unknown},
{"Should be False for (True, True)", True, True, False},
}
for _, test := range tests {
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)
}
})
}
}
// TestNand tests the Nand function.
func TestNand(t *testing.T) {
tests := []struct {
name string
a Trit
b Trit
out Trit
}{
{"Should be True for (False, False)", False, False, True},
{"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, True)", Unknown, True, Unknown},
{"Should be True for (True, False)", True, False, True},
{"Should be Unknown for (True, Unknown)", True, Unknown, Unknown},
{"Should be False for (True, True)", True, True, False},
}
for _, test := range tests {
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)
}
})
}
}
// TestNor tests the Nor function.
func TestNor(t *testing.T) {
tests := []struct {
name string
a Trit
b Trit
out Trit
}{
{"Should be True for (False, False)", False, False, True},
{"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 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},
{"Should be False for (True, True)", True, True, False},
}
for _, test := range tests {
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)
}
})
}
}
// TestNxor tests the Nxor function.
func TestNxor(t *testing.T) {
tests := []struct {
name string
a Trit
b Trit
out Trit
}{
{"Should be True for (False, False)", False, False, True},
{"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, True)", Unknown, True, Unknown},
{"Should be False for (True, False)", True, False, False},
{"Should be Unknown for (True, Unknown)", True, Unknown, Unknown},
{"Should be True for (True, True)", True, True, True},
}
for _, test := range tests {
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)
}
})
}
}
// TestMin tests the Min function.
func TestMin(t *testing.T) {
tests := []struct {
name string
a Trit
b Trit
out Trit
}{
{"Should be False for (False, False)", False, False, False},
{"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, True)", Unknown, True, Unknown},
{"Should be False for (True, False)", True, False, False},
{"Should be Unknown for (True, Unknown)", True, Unknown, Unknown},
{"Should be True for (True, True)", True, True, True},
}
for _, test := range tests {
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)
}
})
}
}
// TestMax tests the Max function.
func TestMax(t *testing.T) {
tests := []struct {
name string
a Trit
b Trit
out Trit
}{
{"Should be False for (False, False)", False, False, False},
{"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 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},
{"Should be True for (True, True)", True, True, True},
}
for _, test := range tests {
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)
}
})
}
}
// TestImp tests the Imp function.
func TestImp(t *testing.T) {
tests := []struct {
name string
a Trit
b Trit
out Trit
}{
{"Should be True for (False, False)", False, False, True},
{"Should be True for (False, Unknown)", False, Unknown, True},
{"Should be True for (False, True)", False, True, True},
{"Should be Unknown for (Unknown, False)", Unknown, False, Unknown},
{"Should be True for (Unknown, Unknown)", Unknown, Unknown, True},
{"Should be True for (Unknown, True)", Unknown, True, True},
{"Should be False for (True, False)", True, False, False},
{"Should be Unknown for (True, Unknown)", True, Unknown, Unknown},
{"Should be True for (True, True)", True, True, True},
}
for _, test := range tests {
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)
}
})
}
}
// TestNimp tests the Nimp function.
func TestNimp(t *testing.T) {
tests := []struct {
name string
a Trit
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,
},
}
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)
}
})
}
}
// TestEq tests the Eq function.
func TestEq(t *testing.T) {
tests := []struct {
name string
a Trit
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},
}
for _, test := range tests {
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)
}
})
}
}
// TestNeq tests the Neq function.
func TestNeq(t *testing.T) {
tests := []struct {
name string
a Trit
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},
}