-
Notifications
You must be signed in to change notification settings - Fork 0
/
videotex_test.go
104 lines (89 loc) · 3.3 KB
/
videotex_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
package minigo
import "testing"
func TestBitReadAt(t *testing.T) {
var b byte = 0b01000001
if BitReadAt(b, 0) != true {
// looking for: 0b01000001
// ^
t.Fatal("wrong value extracted at pos 0")
}
if BitReadAt(b, 6) != true {
// looking for: 0b01000001
// ^
t.Fatal("wrong value extracted at pos 6")
}
if BitReadAt(b, 7) != false {
// looking for: 0b01000001
// ^
t.Fatal("wrong value extracted at pos 7")
}
}
func TestIsByteEven(t *testing.T) {
var evenByte byte = 0b01000001
if IsByteEven(evenByte) != true {
t.Fatalf("wrong parity extracted for even-byte: %d", evenByte)
}
var oddByte byte = 0b01100001
if IsByteEven(oddByte) != false {
t.Fatalf("wrong parity extracted for odd-byte: %d", oddByte)
}
}
func TestBitWriteAt(t *testing.T) {
var originalByte byte = 0b01000001
var expectedByte byte = 0b11000001
if computed := BitWriteAt(originalByte, 7, true); computed != expectedByte {
t.Fatalf("expected result: %b got %b", expectedByte, computed)
}
expectedByte = 0b01100001
if computed := BitWriteAt(originalByte, 5, true); computed != expectedByte {
t.Fatalf("expected result: %b got %b", expectedByte, computed)
}
expectedByte = 0b00000001
if computed := BitWriteAt(originalByte, 6, false); computed != expectedByte {
t.Fatalf("expected result: %b got %b", expectedByte, computed)
}
expectedByte = 0b01000000
if computed := BitWriteAt(originalByte, 0, false); computed != expectedByte {
t.Fatalf("expected result: %b got %b", expectedByte, computed)
}
}
func TestGetByteWithParity(t *testing.T) {
var originalByte byte = 0b01000001
var expectedByte byte = 0b01000001
if computed := SetParity(originalByte); computed != expectedByte {
t.Fatalf("expected result: %b got %b", expectedByte, computed)
}
originalByte = 0b01100001
expectedByte = 0b11100001
if computed := SetParity(originalByte); computed != expectedByte {
t.Fatalf("expected result: %b got %b", expectedByte, computed)
}
originalByte = 0b00000000
expectedByte = 0b00000000
if computed := SetParity(originalByte); computed != expectedByte {
t.Fatalf("expected result: %b got %b", expectedByte, computed)
}
}
func TestCheckByteParity(t *testing.T) {
var goodParityByte byte = 0b01000001
var goodParityRemoved byte = 0b01000001
if computed, err := ValidAndRemoveParity(goodParityByte); computed != goodParityRemoved || err != nil {
t.Fatalf("wrong parity check for %b, expected %b, computed %b, with error: %s", goodParityByte, goodParityRemoved, computed, err.Error())
}
goodParityByte = 0b10010011
goodParityRemoved = 0b00010011
if computed, err := ValidAndRemoveParity(goodParityByte); computed != goodParityRemoved || err != nil {
t.Fatalf("wrong parity check for %b, expected %b, computed %b, with error: %s", goodParityByte, goodParityRemoved, computed, err.Error())
}
var wrongParityByte byte = 0b11000001
var wrongParityRemoved byte = 0b11000001
if computed, err := ValidAndRemoveParity(wrongParityByte); computed != wrongParityRemoved || err == nil {
t.Fatalf("wrong parity check for %b, expected %b, computed %b, with error: %s", goodParityByte, wrongParityRemoved, computed, err.Error())
}
}
func TestCharMapping(t *testing.T) {
c := EncodeRune('A')
if len(c) != 1 || c[0] != 0x41 {
t.Fatalf("recieved %x instead of %x", c, 0x41)
}
}