Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitprincess committed Dec 5, 2022
1 parent dea7f4c commit 3ab7723
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 63 deletions.
4 changes: 2 additions & 2 deletions sort/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
122 changes: 61 additions & 61 deletions sort/sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
}

0 comments on commit 3ab7723

Please sign in to comment.