Add more tests
Some checks failed
Benchmark BufferPool / RunBenchmarks (push) Failing after 1m15s
Run Tests / Test (push) Failing after 1m13s

This commit is contained in:
2024-07-28 19:47:04 +02:00
parent a2f4e9af25
commit e6199da5d6
2 changed files with 49 additions and 28 deletions

View File

@@ -57,22 +57,6 @@ func (c *GSM7Coder) Encode(s string, buf *bytes.Buffer) error {
}
}
return nil
// The issue happens during leap
// 2024/07/28 16:56:12 Index 7 1 7 11100100 00000000
// 2024/07/28 16:56:12 Leap at 7 1 7
// 2024/07/28 16:56:12 Index 8 1 7 11000010 00000000
// 2024/07/28 16:56:12 Shift at 8 1 7
// 2024/07/28 16:56:12 Index 9 2 1 11000010 00111100
// The correct output should be:
// Index 9 2 1 11100001 00111100
// Also
// 2024/07/28 16:58:49 Index 8 1 7 00000000 01100001
// 2024/07/28 16:58:49 Index 8 1 7 11000010 00000000
// 2024/07/28 16:58:49 Shift at 8 1 7
// 2024/07/28 16:58:49 Index 9 2 1 11000010 01111001
// 2024/07/28 16:58:49 Index 9 2 1 11000010 00111100 <-- the LSB 1 that is removed is not added to the previous byte (should be 11100001, not 11000010)
}
func (c *GSM7Coder) Decode(buf *bytes.Buffer) (string, error) {

View File

@@ -5,6 +5,7 @@ import (
"testing"
)
// region encode
func TestGSM7EncodeSimpleASCIIString(t *testing.T) {
coder := &GSM7Coder{}
var buf bytes.Buffer
@@ -18,7 +19,7 @@ func TestGSM7EncodeSimpleASCIIString(t *testing.T) {
}
if !bytes.Equal(buf.Bytes(), expected) {
t.Errorf("Expected %v, but got %v", expected, buf.Bytes())
t.Errorf("Expected '%v', but got '%v'", expected, buf.Bytes())
}
}
@@ -35,7 +36,24 @@ func TestGSM7EncodeComplexASCIIString(t *testing.T) {
}
if !bytes.Equal(buf.Bytes(), expected) {
t.Errorf("Expected %v, but got %v", expected, buf.Bytes())
t.Errorf("Expected '%v', but got '%v'", expected, buf.Bytes())
}
}
func TestGSM7EncodeComplex8nASCIIString(t *testing.T) {
coder := &GSM7Coder{}
var buf bytes.Buffer
input := "Ducks are fucking great, they quacks, O quackers, what the fuck."
expected := []byte{0b11000100, 0b11111010, 0b01111000, 0b00111101, 0b00000111, 0b10000101, 0b11100101, 0b01100101, 0b10010000, 0b10111001, 0b00111110, 0b01011110, 0b10100111, 0b11011101, 0b01100111, 0b11010000, 0b01011001, 0b01011110, 0b00001110, 0b11010011, 0b01011001, 0b00100000, 0b00111010, 0b10111010, 0b10011100, 0b00000111, 0b11000101, 0b11101011, 0b11100001, 0b11110001, 0b01111010, 0b11001110, 0b00000010, 0b00111101, 0b01000001, 0b11110001, 0b01111010, 0b01111000, 0b10111100, 0b00101110, 0b11001011, 0b11100111, 0b00101100, 0b11010000, 0b00011101, 0b00011101, 0b10100110, 0b10000011, 0b11101000, 0b11101000, 0b00110010, 0b11001000, 0b01011100, 0b00011111, 0b10101111, 0b01011101}
err := coder.Encode(input, &buf)
if err != nil {
t.Errorf("Expected no error, but got %v", err)
}
if !bytes.Equal(buf.Bytes(), expected) {
t.Errorf("Expected '%v', but got '%v'", expected, buf.Bytes())
}
}
@@ -52,10 +70,11 @@ func TestGSM7EncodeEmptyString(t *testing.T) {
}
if !bytes.Equal(buf.Bytes(), expected) {
t.Errorf("Expected %v, but got %v", expected, buf.Bytes())
t.Errorf("Expected '%v', but got '%v'", expected, buf.Bytes())
}
}
// region decode
func TestGSM7DecodeSimpleASCIIString(t *testing.T) {
coder := &GSM7Coder{}
var buf bytes.Buffer
@@ -63,14 +82,14 @@ func TestGSM7DecodeSimpleASCIIString(t *testing.T) {
expected := "Sunshine"
buf.Write(input)
output, err := coder.Decode(&buf)
actual, err := coder.Decode(&buf)
if err != nil {
t.Errorf("Expected no error, but got %v", err)
}
if output != expected {
t.Errorf("Expected %v, but got %v", expected, output)
if actual != expected {
t.Errorf("Expected '%v', but got '%v'", expected, actual)
}
}
@@ -81,14 +100,32 @@ func TestGSM7DecodeComplexASCIIString(t *testing.T) {
expected := "Golden rays play, Chasing night away."
buf.Write(input)
output, err := coder.Decode(&buf)
actual, err := coder.Decode(&buf)
if err != nil {
t.Errorf("Expected no error, but got %v", err)
}
if output != expected {
t.Errorf("Expected %v, but got %v", expected, output)
if actual != expected {
t.Errorf("Expected '%v', but got '%v'", expected, actual)
}
}
func TestGSM7DecodeComplex8nASCIIString(t *testing.T) {
coder := &GSM7Coder{}
var buf bytes.Buffer
input := []byte{0b11000100, 0b11111010, 0b01111000, 0b00111101, 0b00000111, 0b10000101, 0b11100101, 0b01100101, 0b10010000, 0b10111001, 0b00111110, 0b01011110, 0b10100111, 0b11011101, 0b01100111, 0b11010000, 0b01011001, 0b01011110, 0b00001110, 0b11010011, 0b01011001, 0b00100000, 0b00111010, 0b10111010, 0b10011100, 0b00000111, 0b11000101, 0b11101011, 0b11100001, 0b11110001, 0b01111010, 0b11001110, 0b00000010, 0b00111101, 0b01000001, 0b11110001, 0b01111010, 0b01111000, 0b10111100, 0b00101110, 0b11001011, 0b11100111, 0b00101100, 0b11010000, 0b00011101, 0b00011101, 0b10100110, 0b10000011, 0b11101000, 0b11101000, 0b00110010, 0b11001000, 0b01011100, 0b00011111, 0b10101111, 0b01011101}
expected := "Ducks are fucking great, they quacks, O quackers, what the fuck."
buf.Write(input)
actual, err := coder.Decode(&buf)
if err != nil {
t.Errorf("Expected no error, but got %v", err)
}
if actual != expected {
t.Errorf("Expected '%v', but got '%v'", expected, actual)
}
}
@@ -97,13 +134,13 @@ func TestGSM7DecodeEmptyString(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
expected := ""
output, err := coder.Decode(buf)
actual, err := coder.Decode(buf)
if err != nil {
t.Errorf("Expected no error, but got %v", err)
}
if output != expected {
t.Errorf("Expected %v, but got %v", expected, output)
if actual != expected {
t.Errorf("Expected '%v', but got '%v'", expected, actual)
}
}