From 3cd55d89271ba4c9a222c7930ae511ce4fc0a83a Mon Sep 17 00:00:00 2001 From: Shun Sakai Date: Fri, 5 Apr 2024 00:49:56 +0900 Subject: [PATCH] Update tests --- lzip_test.go | 62 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/lzip_test.go b/lzip_test.go index 2a14ba6..a9916b2 100644 --- a/lzip_test.go +++ b/lzip_test.go @@ -5,7 +5,6 @@ package lzip_test import ( - "math" "testing" "github.com/sorairolake/lzip-go" @@ -14,75 +13,96 @@ import ( func TestHeaderSize(t *testing.T) { t.Parallel() - if size := lzip.HeaderSize; size != 6 { - t.Errorf("expected header size `%v`, got `%v`", 6, size) + const expected = 6 + + if size := lzip.HeaderSize; size != expected { + t.Errorf("expected header size `%v`, got `%v`", expected, size) } } func TestTrailerSize(t *testing.T) { t.Parallel() - if size := lzip.TrailerSize; size != 20 { - t.Errorf("expected trailer size `%v`, got `%v`", 20, size) + const expected = 20 + + if size := lzip.TrailerSize; size != expected { + t.Errorf("expected trailer size `%v`, got `%v`", expected, size) } } func TestMagic(t *testing.T) { t.Parallel() - if magic := lzip.Magic; magic != "LZIP" { - t.Errorf("expected magic number `%v`, got `%v`", "LZIP", magic) + const expected = "LZIP" + + if magic := lzip.Magic; magic != expected { + t.Errorf("expected magic number `%v`, got `%v`", expected, magic) } } func TestMagicSize(t *testing.T) { t.Parallel() - if size := lzip.MagicSize; size != 4 { - t.Errorf("expected magic number size `%v`, got `%v`", 4, size) + const expected = 4 + + if size := lzip.MagicSize; size != expected { + t.Errorf("expected magic number size `%v`, got `%v`", expected, size) } } func TestVersion(t *testing.T) { t.Parallel() - if v0 := lzip.Version0; v0 != 0 { - t.Errorf("expected version number `%v`, got `%v`", 0, v0) + const ( + expectedV0 = iota + expectedV1 + ) + + if v0 := lzip.Version0; v0 != expectedV0 { + t.Errorf("expected version number `%v`, got `%v`", expectedV0, v0) } - if v1 := lzip.Version1; v1 != 1 { - t.Errorf("expected version number `%v`, got `%v`", 1, v1) + if v1 := lzip.Version1; v1 != expectedV1 { + t.Errorf("expected version number `%v`, got `%v`", expectedV1, v1) } } func TestMinDictSize(t *testing.T) { t.Parallel() - if size := lzip.MinDictSize; size != (1 << 12) { - t.Errorf("expected minimum dictionary size `%v`, got `%v`", (1 << 12), size) + const expected = 1 << 12 + + if size := lzip.MinDictSize; size != expected { + t.Errorf("expected minimum dictionary size `%v`, got `%v`", expected, size) } } func TestMaxDictSize(t *testing.T) { t.Parallel() - if size := lzip.MaxDictSize; size != (1 << 29) { - t.Errorf("expected maximum dictionary size `%v`, got `%v`", (1 << 29), size) + const expected = 1 << 29 + + if size := lzip.MaxDictSize; size != expected { + t.Errorf("expected maximum dictionary size `%v`, got `%v`", expected, size) } } func TestDefaultDictSize(t *testing.T) { t.Parallel() - if size := uint32(lzip.DefaultDictSize); size != (8 * uint32(math.Pow(2.0, 20.0))) { - t.Errorf("expected default dictionary size `%v`, got `%v`", (8 * uint32(math.Pow(2.0, 20.0))), size) + const expected = 8 * (1 << 20) + + if size := lzip.DefaultDictSize; size != expected { + t.Errorf("expected default dictionary size `%v`, got `%v`", expected, size) } } func TestMaxMemberSize(t *testing.T) { t.Parallel() - if size := uint64(lzip.MaxMemberSize); size != (2 * uint64(math.Pow(2.0, 50.0))) { - t.Errorf("expected maximum member size `%v`, got `%v`", (2 * uint64(math.Pow(2.0, 50.0))), size) + const expected = 2 * (1 << 50) + + if size := lzip.MaxMemberSize; size != expected { + t.Errorf("expected maximum member size `%v`, got `%v`", expected, size) } }