Debian Codegraph @

flags_test.go

raw
1 package tensor
2
3 import "testing"
4
5 func TestMemoryFlag(t *testing.T) {
6 var defaultFlag MemoryFlag
7 if defaultFlag.manuallyManaged() || !defaultFlag.nativelyAccessible() {
8 t.Errorf("Something went wrong with the creation of flags")
9 }
10
11 a := ManuallyManaged
12 if !a.manuallyManaged() {
13 t.Errorf("Expected ManuallyManaged to be true")
14 }
15 if !a.nativelyAccessible() {
16 t.Errorf("Expected ManuallyManaged to be nativelyAccessible")
17 }
18
19 b := NativelyInaccessible
20 if b.manuallyManaged() {
21 t.Errorf("Expected NativelyInaccessible to not be manually managed")
22 }
23 if b.nativelyAccessible() {
24 t.Errorf("Expected NativelyInaccessible to be false %v", b.nativelyAccessible())
25 }
26
27 c := MakeMemoryFlag(ManuallyManaged, NativelyInaccessible)
28 if !c.manuallyManaged() {
29 t.Errorf("Expected c to be manually managed")
30 }
31 if c.nativelyAccessible() {
32 t.Errorf("Expected c to be natively inaccessible")
33 }
34 }
35
36 func TestDataOrder(t *testing.T) {
37 var defaultFlag DataOrder
38 if defaultFlag.IsColMajor() || defaultFlag.IsNotContiguous() || defaultFlag.IsTransposed() {
39 t.Error("Expected default flag to be row major and contiguous and not transposed")
40 }
41 if !(defaultFlag.IsRowMajor() && defaultFlag.IsContiguous()) {
42 t.Error("Expected default flag to be row major and contiguous")
43 }
44 if defaultFlag.String() != "Contiguous, RowMajor" {
45 t.Errorf("Expected string is \"Contiguous, RowMajor\". Got %q", defaultFlag.String())
46 }
47
48 ncrm := MakeDataOrder(NonContiguous)
49 if ncrm.IsColMajor() || ncrm.IsContiguous() {
50 t.Error("Expected noncontiguous row major.")
51 }
52 if ncrm.String() != "NonContiguous, RowMajor" {
53 t.Errorf("Expected string is \"NonContiguous, RowMajor\". Got %q", defaultFlag.String())
54 }
55
56 cm := ColMajor
57 if cm.IsRowMajor() {
58 t.Error("colMajor cannot be rowMajor")
59 }
60 if cm.IsNotContiguous() {
61 t.Error("ColMajor by default is contiguous")
62 }
63 if cm.String() != "Contiguous, ColMajor" {
64 t.Errorf(`Expected string is "Contiguous, ColMajor". Got %q`, cm.String())
65 }
66
67 // check toggle
68 rm := cm.toggleColMajor()
69 if rm.IsColMajor() {
70 t.Errorf("toggled cm should be rm")
71 }
72
73 cm = rm.toggleColMajor()
74 if cm.IsRowMajor() {
75 t.Errorf("toggled rm should be cm")
76 }
77
78 transposed := MakeDataOrder(Transposed)
79 if !transposed.IsTransposed() {
80 t.Error("Expected transposed flag to be set")
81 }
82 if transposed.String() != "Contiguous, RowMajorᵀ" {
83 t.Errorf("Expected string is \"Contiguous, RowMajorᵀ\". Got %q", defaultFlag.String())
84 }
85 untransposed := transposed.clearTransposed()
86 if untransposed != defaultFlag {
87 t.Error("Expected default flag after untransposing")
88 }
89
90 }