2024-03-08 16:03:02 +01:00
|
|
|
package apg
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestConvertByteToWord(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
char byte
|
|
|
|
want string
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "UpperCaseChar",
|
|
|
|
char: 'A',
|
|
|
|
want: alphabetNames['A'],
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "LowerCaseChar",
|
|
|
|
char: 'a',
|
|
|
|
want: strings.ToLower(alphabetNames['A']),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "NonAlphaChar",
|
|
|
|
char: '(',
|
|
|
|
want: symbNumNames['('],
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "UnsupportedChar",
|
|
|
|
char: 'ü',
|
|
|
|
want: "",
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
got, err := ConvertByteToWord(tt.char)
|
|
|
|
if (err != nil) != tt.wantErr {
|
2024-03-08 16:04:16 +01:00
|
|
|
t.Errorf("ConvertByteToWord() error = %s, wantErr %t", err, tt.wantErr)
|
2024-03-08 16:03:02 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if got != tt.want {
|
2024-03-08 16:04:16 +01:00
|
|
|
t.Errorf("ConvertByteToWord() got = %s, want %s", got, tt.want)
|
2024-03-08 16:03:02 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|