diff --git a/encoding/gsm7_test.go b/encoding/gsm7_test.go index 6a5b3fb..d982e16 100644 --- a/encoding/gsm7_test.go +++ b/encoding/gsm7_test.go @@ -5,13 +5,23 @@ import ( "testing" ) +var ( + short8nString = "Sunshine" + longNot8nString = "Golden rays play, Chasing night away." + long8nString = "Ducks are fucking great, they quacks, O quackers, what the fuck." + + short8nStringEncodedBytes = []byte{0b11010011, 0b10111010, 0b01111011, 0b10001110, 0b01001110, 0b10111011, 0b11001011} + longNot8nStringEncodedBytes = []byte{0b11000111, 0b00110111, 0b10011011, 0b01011100, 0b01110110, 0b10000011, 0b11100100, 0b11100001, 0b11111100, 0b00011100, 0b00000100, 0b01100111, 0b10000111, 0b11110011, 0b00101100, 0b11010000, 0b00010000, 0b00011101, 0b10011110, 0b10100111, 0b11011101, 0b01100111, 0b10010000, 0b00111011, 0b01111101, 0b01000110, 0b11010011, 0b01000001, 0b11100001, 0b01111011, 0b00111000, 0b11101111, 0b00000010} + long8nStringEncodedBytes = []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} +) + // region encode func TestGSM7EncodeSimpleASCIIString(t *testing.T) { coder := &GSM7Coder{} var buf bytes.Buffer - input := "Sunshine" + input := short8nString - expected := []byte{0b11010011, 0b10111010, 0b01111011, 0b10001110, 0b01001110, 0b10111011, 0b11001011} + expected := short8nStringEncodedBytes err := coder.Encode(input, &buf) if err != nil { @@ -26,9 +36,9 @@ func TestGSM7EncodeSimpleASCIIString(t *testing.T) { func TestGSM7EncodeComplexASCIIString(t *testing.T) { coder := &GSM7Coder{} var buf bytes.Buffer - input := "Golden rays play, Chasing night away." + input := longNot8nString - expected := []byte{0b11000111, 0b00110111, 0b10011011, 0b01011100, 0b01110110, 0b10000011, 0b11100100, 0b11100001, 0b11111100, 0b00011100, 0b00000100, 0b01100111, 0b10000111, 0b11110011, 0b00101100, 0b11010000, 0b00010000, 0b00011101, 0b10011110, 0b10100111, 0b11011101, 0b01100111, 0b10010000, 0b00111011, 0b01111101, 0b01000110, 0b11010011, 0b01000001, 0b11100001, 0b01111011, 0b00111000, 0b11101111, 0b00000010} + expected := longNot8nStringEncodedBytes err := coder.Encode(input, &buf) if err != nil { @@ -45,7 +55,7 @@ func TestGSM7EncodeComplex8nASCIIString(t *testing.T) { 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} + expected := long8nStringEncodedBytes err := coder.Encode(input, &buf) if err != nil { @@ -78,9 +88,9 @@ func TestGSM7EncodeEmptyString(t *testing.T) { func TestGSM7DecodeSimpleASCIIString(t *testing.T) { coder := &GSM7Coder{} var buf bytes.Buffer - input := []byte{0b11010011, 0b10111010, 0b01111011, 0b10001110, 0b01001110, 0b10111011, 0b11001011} + input := short8nStringEncodedBytes - expected := "Sunshine" + expected := short8nString buf.Write(input) actual, err := coder.Decode(&buf) @@ -96,9 +106,9 @@ func TestGSM7DecodeSimpleASCIIString(t *testing.T) { // func TestGSM7DecodeComplexASCIIString(t *testing.T) { // coder := &GSM7Coder{} // var buf bytes.Buffer -// input := []byte{0b11000111, 0b00110111, 0b10011011, 0b01011100, 0b01110110, 0b10000011, 0b11100100, 0b11100001, 0b11111100, 0b00011100, 0b00000100, 0b01100111, 0b10000111, 0b11110011, 0b00101100, 0b11010000, 0b00010000, 0b00011101, 0b10011110, 0b10100111, 0b11011101, 0b01100111, 0b10010000, 0b00111011, 0b01111101, 0b01000110, 0b11010011, 0b01000001, 0b11100001, 0b01111011, 0b00111000, 0b11101111, 0b00000010} +// input := longNot8nStringEncodedBytes -// expected := "Golden rays play, Chasing night away." +// expected := longNot8nString // buf.Write(input) // actual, err := coder.Decode(&buf) @@ -114,9 +124,9 @@ func TestGSM7DecodeSimpleASCIIString(t *testing.T) { // 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} +// input := long8nStringEncodedBytes -// expected := "Ducks are fucking great, they quacks, O quackers, what the fuck." +// expected := long8nString // buf.Write(input) // actual, err := coder.Decode(&buf) @@ -221,7 +231,7 @@ func TestDeletesLastValue(t *testing.T) { // region misc tests func TestGSM7EncodesIntoSmallString(t *testing.T) { - input := "Sunshine" + input := short8nString expected := 7 actual := EncodesInto(&input) if actual != expected { @@ -230,7 +240,7 @@ func TestGSM7EncodesIntoSmallString(t *testing.T) { } func TestGSM7EncodesIntoLargerNot8nString(t *testing.T) { - input := "Golden rays play, Chasing night away." + input := longNot8nString expected := 33 actual := EncodesInto(&input) if actual != expected { @@ -239,7 +249,7 @@ func TestGSM7EncodesIntoLargerNot8nString(t *testing.T) { } func TestGSM7EncodesIntoLarger8nString(t *testing.T) { - input := "Ducks are fucking great, they quacks, O quackers, what the fuck." + input := long8nString expected := 56 actual := EncodesInto(&input) if actual != expected { @@ -248,7 +258,7 @@ func TestGSM7EncodesIntoLarger8nString(t *testing.T) { } func TestGSM7DecodesIntoSmallString(t *testing.T) { - input := []byte{0b11010011, 0b10111010, 0b01111011, 0b10001110, 0b01001110, 0b10111011, 0b11001011} + input := short8nStringEncodedBytes expected := 8 actual := DecodesInto(bytes.NewBuffer(input)) if actual != expected { @@ -257,7 +267,7 @@ func TestGSM7DecodesIntoSmallString(t *testing.T) { } func TestGSM7DecodesIntoLargerNot8nString(t *testing.T) { - input := []byte{0b11000111, 0b00110111, 0b10011011, 0b01011100, 0b01110110, 0b10000011, 0b11100100, 0b11100001, 0b11111100, 0b00011100, 0b00000100, 0b01100111, 0b10000111, 0b11110011, 0b00101100, 0b11010000, 0b00010000, 0b00011101, 0b10011110, 0b10100111, 0b11011101, 0b01100111, 0b10010000, 0b00111011, 0b01111101, 0b01000110, 0b11010011, 0b01000001, 0b11100001, 0b01111011, 0b00111000, 0b11101111, 0b00000010} + input := longNot8nStringEncodedBytes expected := 37 actual := DecodesInto(bytes.NewBuffer(input)) if actual != expected { @@ -266,7 +276,7 @@ func TestGSM7DecodesIntoLargerNot8nString(t *testing.T) { } func TestGSM7DecodesIntoLarger8nString(t *testing.T) { - 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} + input := long8nStringEncodedBytes expected := 64 actual := DecodesInto(bytes.NewBuffer(input)) if actual != expected { @@ -278,7 +288,7 @@ func TestGSM7DecodesIntoLarger8nString(t *testing.T) { func BenchmarkGSM7EncodeSimpleASCIIString(b *testing.B) { coder := &GSM7Coder{} var buf bytes.Buffer - input := "Sunshine" + input := short8nString b.ResetTimer() for i := 0; i < b.N; i++ { @@ -289,7 +299,7 @@ func BenchmarkGSM7EncodeSimpleASCIIString(b *testing.B) { func BenchmarkGSM7EncodeComplexASCIIString(b *testing.B) { coder := &GSM7Coder{} var buf bytes.Buffer - input := "Golden rays play, Chasing night away." + input := longNot8nString b.ResetTimer() for i := 0; i < b.N; i++ { @@ -300,7 +310,7 @@ func BenchmarkGSM7EncodeComplexASCIIString(b *testing.B) { func BenchmarkGSM7EncodeComplex8nASCIIString(b *testing.B) { coder := &GSM7Coder{} var buf bytes.Buffer - input := "Ducks are fucking great, they quacks, O quackers, what the fuck." + input := long8nString b.ResetTimer() for i := 0; i < b.N; i++ {