From 3ab772397f672b5c2ea7a4e3adc12f7d58f7f943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=B0=BD=ED=95=99?= Date: Mon, 5 Dec 2022 15:10:01 +0900 Subject: [PATCH] . --- sort/sort.go | 4 +- sort/sort_test.go | 122 +++++++++++++++++++++++----------------------- 2 files changed, 63 insertions(+), 63 deletions(-) diff --git a/sort/sort.go b/sort/sort.go index c852099..23da32d 100644 --- a/sort/sort.go +++ b/sort/sort.go @@ -19,8 +19,8 @@ type SnumSort struct { } func (t *SnumSort) UnmarshalJSON(bt []byte) error { - if len(bt) < DEF_lenTotalMin+2 { - return errors.New("too short") + if len(bt) < DEF_lenTotalMin+2 || bt[0] != '"' || bt[len(bt)-1] != '"' { + return errors.New("invalid format") } enc, err := hex.DecodeString(string(bt[1 : len(bt)-1])) if err != nil { diff --git a/sort/sort_test.go b/sort/sort_test.go index cc9400d..12160f5 100644 --- a/sort/sort_test.go +++ b/sort/sort_test.go @@ -12,67 +12,6 @@ import ( "github.com/stretchr/testify/require" ) -func Test_encode_decode(t *testing.T) { - fn_test := func(sn string) { - snumSort := NewSnumSort(snum.NewSnum(sn)) - - enc, err := json.MarshalIndent(&snumSort, "", "\t") - fmt.Println(sn, string(enc)) - require.NoError(t, err) - - snumSortNew := NewSnumSort(snum.NewSnum(0)) - err = json.Unmarshal(enc, &snumSortNew) - require.NoError(t, err) - - require.Equal(t, snumSort.String(), snumSortNew.String()) - } - - fn_test("11") - fn_test("10.00000000000000000000000000000001") - fn_test("10") - fn_test("1.2") - fn_test("1.1") - fn_test("1") - fn_test("0.1") - fn_test("0.123123") - fn_test("0.0123123") - fn_test("0.00123123") - fn_test("0.000123123") - fn_test("0.000000000000000000000000000001") - fn_test("0.0000000000000000000000000000001") - fn_test("0.00000000000000000000000000099999") - fn_test("0.00000000000000000000000000009999") - fn_test("0.00000000000000000000000000000999") - fn_test("0.00000000000000000000000000000099") - fn_test("0.00000000000000000000000000000009") - fn_test("0.00000000000000000000000000000001") - fn_test("0") - fn_test("-0.00000000000000000000000000000001") - fn_test("-0.00000000000000000000000000000009") - fn_test("-0.00000000000000000000000000000099") - fn_test("-0.00000000000000000000000000000999") - fn_test("-0.00000000000000000000000000009999") - fn_test("-0.00000000000000000000000000099999") - fn_test("-0.0000000000000000000000000000001") - fn_test("-0.000000000000000000000000000001") - fn_test("-0.000123123") - fn_test("-0.00123123") - fn_test("-0.0123123") - fn_test("-0.1") - fn_test("-0.123123") - fn_test("-1") - fn_test("-1.1") - fn_test("-1.11") - fn_test("-1.111") - fn_test("-1.1111") - fn_test("-1.2") - fn_test("-10") - fn_test("-10.00000000000000000000000000000011") - fn_test("-10.00000000000000000000000000000010") - fn_test("-10.00000000000000000000000000000001") - fn_test("-11") -} - // Byte_encode, Byte_decode // string -> bigint -> binary -> bigint -> string func TestSort_encode_decode(t *testing.T) { @@ -335,3 +274,64 @@ func TestSort_header(t *testing.T) { fn(96, 0) // 96 자리 정수 fn(128, 32) // 96 자리 정수 + 32 자리 소수 } + +func TestSort_json(t *testing.T) { + fn_test := func(sn string) { + snumSort := NewSnumSort(snum.NewSnum(sn)) + + enc, err := json.MarshalIndent(&snumSort, "", "\t") + fmt.Println(sn, string(enc)) + require.NoError(t, err) + + snumSortNew := NewSnumSort(snum.NewSnum(0)) + err = json.Unmarshal(enc, &snumSortNew) + require.NoError(t, err) + + require.Equal(t, snumSort.String(), snumSortNew.String()) + } + + fn_test("11") + fn_test("10.00000000000000000000000000000001") + fn_test("10") + fn_test("1.2") + fn_test("1.1") + fn_test("1") + fn_test("0.1") + fn_test("0.123123") + fn_test("0.0123123") + fn_test("0.00123123") + fn_test("0.000123123") + fn_test("0.000000000000000000000000000001") + fn_test("0.0000000000000000000000000000001") + fn_test("0.00000000000000000000000000099999") + fn_test("0.00000000000000000000000000009999") + fn_test("0.00000000000000000000000000000999") + fn_test("0.00000000000000000000000000000099") + fn_test("0.00000000000000000000000000000009") + fn_test("0.00000000000000000000000000000001") + fn_test("0") + fn_test("-0.00000000000000000000000000000001") + fn_test("-0.00000000000000000000000000000009") + fn_test("-0.00000000000000000000000000000099") + fn_test("-0.00000000000000000000000000000999") + fn_test("-0.00000000000000000000000000009999") + fn_test("-0.00000000000000000000000000099999") + fn_test("-0.0000000000000000000000000000001") + fn_test("-0.000000000000000000000000000001") + fn_test("-0.000123123") + fn_test("-0.00123123") + fn_test("-0.0123123") + fn_test("-0.1") + fn_test("-0.123123") + fn_test("-1") + fn_test("-1.1") + fn_test("-1.11") + fn_test("-1.111") + fn_test("-1.1111") + fn_test("-1.2") + fn_test("-10") + fn_test("-10.00000000000000000000000000000011") + fn_test("-10.00000000000000000000000000000010") + fn_test("-10.00000000000000000000000000000001") + fn_test("-11") +}