mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-10-02 16:15:58 -04:00
Replaces comparisons with assertions
This commit is contained in:
parent
bfa9c34ecc
commit
3b26d825d2
@ -1,6 +1,10 @@
|
|||||||
package d2datautils
|
package d2datautils
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
var testData = []byte{33, 23, 4, 33, 192, 243}
|
var testData = []byte{33, 23, 4, 33, 192, 243}
|
||||||
|
|
||||||
@ -9,9 +13,7 @@ func TestBitmuncherCopy(t *testing.T) {
|
|||||||
bm2 := CopyBitMuncher(bm1)
|
bm2 := CopyBitMuncher(bm1)
|
||||||
|
|
||||||
for i := range bm1.data {
|
for i := range bm1.data {
|
||||||
if bm1.data[i] != bm2.data[i] {
|
assert.Equal(t, bm1.data[i], bm2.data[i], "original bitmuncher isn't equal to copied")
|
||||||
t.Fatal("original bitmuncher isn't equal to copied")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,18 +21,14 @@ func TestBitmuncherSetOffset(t *testing.T) {
|
|||||||
bm := CreateBitMuncher(testData, 0)
|
bm := CreateBitMuncher(testData, 0)
|
||||||
bm.SetOffset(5)
|
bm.SetOffset(5)
|
||||||
|
|
||||||
if bm.Offset() != 5 {
|
assert.Equal(t, bm.Offset(), 5, "Set Offset method didn't set offset to expected number")
|
||||||
t.Fatal("Set Offset method didn't set offset to expected number")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBitmuncherSteBitsRead(t *testing.T) {
|
func TestBitmuncherSteBitsRead(t *testing.T) {
|
||||||
bm := CreateBitMuncher(testData, 0)
|
bm := CreateBitMuncher(testData, 0)
|
||||||
bm.SetBitsRead(8)
|
bm.SetBitsRead(8)
|
||||||
|
|
||||||
if bm.BitsRead() != 8 {
|
assert.Equal(t, bm.BitsRead(), 8, "Set bits read method didn't set bits read to expected value")
|
||||||
t.Fatal("Set bits read method didn't set bits read to expected value")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBitmuncherReadBit(t *testing.T) {
|
func TestBitmuncherReadBit(t *testing.T) {
|
||||||
@ -43,55 +41,37 @@ func TestBitmuncherReadBit(t *testing.T) {
|
|||||||
result |= byte(v) << byte(i)
|
result |= byte(v) << byte(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
if result != testData[0] {
|
assert.Equal(t, result, testData[0], "result of rpeated 8 times get bit didn't return expected byte")
|
||||||
t.Fatal("result of rpeated 8 times get bit didn't return expected byte")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBitmuncherGetBits(t *testing.T) {
|
func TestBitmuncherGetBits(t *testing.T) {
|
||||||
bm := CreateBitMuncher(testData, 0)
|
bm := CreateBitMuncher(testData, 0)
|
||||||
|
|
||||||
if byte(bm.GetBits(bitsPerByte)) != testData[0] {
|
assert.Equal(t, byte(bm.GetBits(bitsPerByte)), testData[0], "get bits didn't return expected value")
|
||||||
t.Fatal("get bits didn't return expected value")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBitmuncherGetNoBits(t *testing.T) {
|
func TestBitmuncherGetNoBits(t *testing.T) {
|
||||||
bm := CreateBitMuncher(testData, 0)
|
bm := CreateBitMuncher(testData, 0)
|
||||||
|
|
||||||
if bm.GetBits(0) != 0 {
|
assert.Equal(t, bm.GetBits(0), uint32(0), "get bits didn't return expected value: 0")
|
||||||
t.Fatal("get bits didn't return expected value: 0")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBitmuncherGetSignedBits(t *testing.T) {
|
func TestBitmuncherGetSignedBits(t *testing.T) {
|
||||||
bm := CreateBitMuncher(testData, 0)
|
bm := CreateBitMuncher(testData, 0)
|
||||||
|
|
||||||
result := bm.GetSignedBits(6)
|
assert.Equal(t, bm.GetSignedBits(6), -31, "get signed bits didn't return expected value")
|
||||||
expected := -31
|
|
||||||
if result != expected {
|
|
||||||
t.Fatal("get signed bits didn't return expected value", result, expected)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBitmuncherGetNoSignedBits(t *testing.T) {
|
func TestBitmuncherGetNoSignedBits(t *testing.T) {
|
||||||
bm := CreateBitMuncher(testData, 0)
|
bm := CreateBitMuncher(testData, 0)
|
||||||
|
|
||||||
result := bm.GetSignedBits(0)
|
assert.Equal(t, bm.GetSignedBits(0), 0, "get signed bits didn't return expected value")
|
||||||
expected := 0
|
|
||||||
if result != expected {
|
|
||||||
t.Fatal("get signed bits didn't return expected value", result, expected)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBitmuncherGetOneSignedBit(t *testing.T) {
|
func TestBitmuncherGetOneSignedBit(t *testing.T) {
|
||||||
bm := CreateBitMuncher(testData, 0)
|
bm := CreateBitMuncher(testData, 0)
|
||||||
|
|
||||||
result := bm.GetSignedBits(1)
|
assert.Equal(t, bm.GetSignedBits(1), -1, "get signed bits didn't return expected value")
|
||||||
expected := -1
|
|
||||||
if result != expected {
|
|
||||||
t.Fatal("get signed bits didn't return expected value", result, expected)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBitmuncherSkipBits(t *testing.T) {
|
func TestBitmuncherSkipBits(t *testing.T) {
|
||||||
@ -99,9 +79,7 @@ func TestBitmuncherSkipBits(t *testing.T) {
|
|||||||
|
|
||||||
bm.SkipBits(bitsPerByte)
|
bm.SkipBits(bitsPerByte)
|
||||||
|
|
||||||
if bm.GetByte() != testData[1] {
|
assert.Equal(t, bm.GetByte(), testData[1], "skipping 8 bits didn't moved bit muncher's position into next byte")
|
||||||
t.Fatal("skipping 8 bits didn't moved bit muncher's position into next byte")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBitmuncherGetInt32(t *testing.T) {
|
func TestBitmuncherGetInt32(t *testing.T) {
|
||||||
@ -113,9 +91,7 @@ func TestBitmuncherGetInt32(t *testing.T) {
|
|||||||
testInt |= int32(testData[i]) << int32(bitsPerByte*i)
|
testInt |= int32(testData[i]) << int32(bitsPerByte*i)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bm.GetInt32() != testInt {
|
assert.Equal(t, bm.GetInt32(), testInt, "int32 value wasn't returned properly")
|
||||||
t.Fatal("int32 value wasn't returned properly")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBitmuncherGetUint32(t *testing.T) {
|
func TestBitmuncherGetUint32(t *testing.T) {
|
||||||
@ -127,7 +103,5 @@ func TestBitmuncherGetUint32(t *testing.T) {
|
|||||||
testUint |= uint32(testData[i]) << uint32(bitsPerByte*i)
|
testUint |= uint32(testData[i]) << uint32(bitsPerByte*i)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bm.GetUInt32() != testUint {
|
assert.Equal(t, bm.GetUInt32(), testUint, "uint32 value wasn't returned properly")
|
||||||
t.Fatal("uint32 value wasn't returned properly")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user