correction

master
Charles Iliya Krempeaux 2023-10-27 11:50:51 -07:00
parent 929e078111
commit d1077fe542
5 changed files with 238 additions and 23 deletions

View File

@ -1,5 +1,9 @@
package hexadeca package hexadeca
import (
"sourcecode.social/reiver/go-hexadeca/symbols/byte"
)
// SymbolLowerCase is used with hexadeca.EncodeByte() to encode a byte into hexadecimal symbols using lower-case symbols from ASCII / Unicode UTF-8. // SymbolLowerCase is used with hexadeca.EncodeByte() to encode a byte into hexadecimal symbols using lower-case symbols from ASCII / Unicode UTF-8.
// I.e., // I.e.,
// //
@ -11,20 +15,9 @@ package hexadeca
// //
// If value was 254 (== 0xFE) then mostSignificiant would be 'f' and and leastSignificant would be 'e'. // If value was 254 (== 0xFE) then mostSignificiant would be 'f' and and leastSignificant would be 'e'.
func SymbolLowerCase(value byte) rune { func SymbolLowerCase(value byte) rune {
return rune(symbolLowerCase(value)) return rune(bytesymbols.LowerCase(value))
} }
func symbolLowerCase(value byte) byte {
const table string = "0123456789abcdef"
var index int = int(value) % len(table)
var result byte = table[index]
return result
}
// SymbolPersian is used with hexadeca.EncodeByte() to encode a byte into hexadecimal symbols using Persian symbols from Unicode UTF-8. // SymbolPersian is used with hexadeca.EncodeByte() to encode a byte into hexadecimal symbols using Persian symbols from Unicode UTF-8.
// I.e., // I.e.,
// //
@ -73,15 +66,5 @@ func SymbolPersian(value byte) rune {
// //
// If value was 254 (== 0xFE) then mostSignificiant would be 'F' and and leastSignificant would be 'E'. // If value was 254 (== 0xFE) then mostSignificiant would be 'F' and and leastSignificant would be 'E'.
func SymbolUpperCase(value byte) rune { func SymbolUpperCase(value byte) rune {
return rune(symbolUpperCase(value)) return rune(bytesymbols.UpperCase(value))
}
func symbolUpperCase(value byte) byte {
const table string = "0123456789ABCDEF"
var index int = int(value) % len(table)
var result byte = table[index]
return result
} }

View File

@ -0,0 +1,21 @@
package bytesymbols
// LowerCase is used with hexadeca.EncodeByte() to encode a byte into hexadecimal symbols using lower-case symbols from ASCII / Unicode UTF-8.
// I.e.,
//
// '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
//
// Example usage:
//
// mostSignificiant, leastSignificant := hexadeca.EncodeByte(value, bytesymbols.LowerCase)
//
// If value was 254 (== 0xFE) then mostSignificiant would be 'f' and and leastSignificant would be 'e'.
func LowerCase(value byte) byte {
const table string = "0123456789abcdef"
var index int = int(value) % len(table)
var result byte = table[index]
return result
}

View File

@ -0,0 +1,95 @@
package bytesymbols_test
import (
"testing"
"sourcecode.social/reiver/go-hexadeca/symbols/byte"
)
func TestSymbolLowerCase(t *testing.T) {
tests := []struct{
Value byte
Expected byte
}{
{
Value: 0,
Expected: '0',
},
{
Value: 1,
Expected: '1',
},
{
Value: 2,
Expected: '2',
},
{
Value: 3,
Expected: '3',
},
{
Value: 4,
Expected: '4',
},
{
Value: 5,
Expected: '5',
},
{
Value: 6,
Expected: '6',
},
{
Value: 7,
Expected: '7',
},
{
Value: 8,
Expected: '8',
},
{
Value: 9,
Expected: '9',
},
{
Value: 10,
Expected: 'a',
},
{
Value: 11,
Expected: 'b',
},
{
Value: 12,
Expected: 'c',
},
{
Value: 13,
Expected: 'd',
},
{
Value: 14,
Expected: 'e',
},
{
Value: 15,
Expected: 'f',
},
}
for testNumber, test := range tests {
actual := bytesymbols.LowerCase(test.Value)
expected := test.Expected
if expected != actual {
t.Errorf("For test #%d, the actual value is not what was expected.", testNumber)
t.Logf("EXPECTED: %q (%d)", expected, expected)
t.Logf("ACTUAL: %q (%d)", actual, actual)
t.Logf("VALUE: %x (%d)", test.Value, test.Value)
continue
}
}
}

View File

@ -0,0 +1,21 @@
package bytesymbols
// UpperCase is used with hexadeca.EncodeByte() to encode a byte into hexadecimal symbols using upper-case symbols from ASCII / Unicode UTF-8.
// I.e.,
//
// '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
//
// Example usage:
//
// mostSignificiant, leastSignificant := hexadeca.EncodeByte(value, bytesymbols.UpperCase)
//
// If value was 254 (== 0xFE) then mostSignificiant would be 'f' and and leastSignificant would be 'e'.
func UpperCase(value byte) byte {
const table string = "0123456789ABCDEF"
var index int = int(value) % len(table)
var result byte = table[index]
return result
}

View File

@ -0,0 +1,95 @@
package bytesymbols_test
import (
"testing"
"sourcecode.social/reiver/go-hexadeca/symbols/byte"
)
func TestSymbolUpperCase(t *testing.T) {
tests := []struct{
Value byte
Expected byte
}{
{
Value: 0,
Expected: '0',
},
{
Value: 1,
Expected: '1',
},
{
Value: 2,
Expected: '2',
},
{
Value: 3,
Expected: '3',
},
{
Value: 4,
Expected: '4',
},
{
Value: 5,
Expected: '5',
},
{
Value: 6,
Expected: '6',
},
{
Value: 7,
Expected: '7',
},
{
Value: 8,
Expected: '8',
},
{
Value: 9,
Expected: '9',
},
{
Value: 10,
Expected: 'A',
},
{
Value: 11,
Expected: 'B',
},
{
Value: 12,
Expected: 'C',
},
{
Value: 13,
Expected: 'D',
},
{
Value: 14,
Expected: 'E',
},
{
Value: 15,
Expected: 'F',
},
}
for testNumber, test := range tests {
actual := bytesymbols.UpperCase(test.Value)
expected := test.Expected
if expected != actual {
t.Errorf("For test #%d, the actual value is not what was expected.", testNumber)
t.Logf("EXPECTED: %q (%d)", expected, expected)
t.Logf("ACTUAL: %q (%d)", actual, actual)
t.Logf("VALUE: %x (%d)", test.Value, test.Value)
continue
}
}
}