blob: 4560dc74d0f16934161950dd7f68ea36e6f24ed6 [file] [log] [blame]
Juha Hyttinenff8dccd2019-12-10 14:34:07 +02001/*
2==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17==================================================================================
18*/
19
20package conv
21
22import (
23 "os"
24 "testing"
25)
26
27// Test cases
28func TestMain(m *testing.M) {
29 code := m.Run()
30 os.Exit(code)
31}
32
33func TestBcdEven(t *testing.T) {
34
35 bcd := NewBcd("0123456789??????")
36 bcdbuf := bcd.Encode("123456")
37 if len(bcdbuf) == 0 {
38 t.Errorf("TestBcdEven: bcd Encode failed")
39 }
40
41 bcdstr := bcd.Decode(bcdbuf)
42 if bcdstr != string("123456") {
43 t.Errorf("TestBcdEven: bcd Decode failed: got %s expect %s", bcdstr, string("123456"))
44 }
45
46}
47
48func TestBcdUnEven1(t *testing.T) {
49
50 bcd := NewBcd("0123456789??????")
51 bcdbuf := bcd.Encode("12345")
52 if len(bcdbuf) == 0 {
53 t.Errorf("TestBcdUnEven1: bcd Encode failed")
54 }
55
56 bcdstr := bcd.Decode(bcdbuf)
57 if bcdstr != string("12345?") {
58 t.Errorf("TestBcdUnEven1: bcd Decode failed: got %s expect %s", bcdstr, string("12345?"))
59 }
60}
61
62func TestBcdUnEven2(t *testing.T) {
63
64 bcd := NewBcd("0123456789?????f")
65 bcdbuf := bcd.Encode("12345f")
66 if len(bcdbuf) == 0 {
67 t.Errorf("TestBcdUnEven2: bcd Encode failed")
68 }
69
70 bcdstr := bcd.Decode(bcdbuf)
71 if bcdstr != string("12345f") {
72 t.Errorf("TestBcdUnEven2: bcd Decode failed: got %s expect %s", bcdstr, string("12345f"))
73 }
74}