aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


server/movement_1491_test.go (1031B)


      1 package main
      2 
      3 import (
      4 	"bytes"
      5 	"encoding/binary"
      6 	"encoding/hex"
      7 	"math"
      8 	"testing"
      9 )
     10 
     11 func TestDecodeMovement1491Capture(t *testing.T) {
     12 	packet, _ := hex.DecodeString("011e0001060ff00000c4e00000187d0000")
     13 
     14 	decoded := decodeMovement1491(packet)
     15 
     16 	if len(decoded) != 40 || binary.BigEndian.Uint32(decoded[:4]) != 1 {
     17 		t.Fatalf("Unexpected decoded movement: %x", decoded)
     18 	}
     19 	for i, expected := range []float32{960, 16.375, 510, 0, -0.9238911, 0, 0.3826555, 0, 0} {
     20 		actual := math.Float32frombits(binary.BigEndian.Uint32(decoded[4+i*4:]))
     21 		if math.Abs(float64(actual-expected)) > 0.000001 {
     22 			t.Fatalf("Field %d: got %v, want %v", i, actual, expected)
     23 		}
     24 	}
     25 }
     26 
     27 func TestEncodeMovement1491NPC(t *testing.T) {
     28 	body, _ := hex.DecodeString("0000000244700000c184000043ff00000000000000000000000000003f8000003e80000000000000")
     29 	expected, _ := hex.DecodeString("021e00fef80ff000000000000040000200")
     30 
     31 	encoded := encodeMovement1491(body)
     32 
     33 	if !bytes.Equal(encoded, expected) {
     34 		t.Fatalf("Got %x, want %x", encoded, expected)
     35 	}
     36 }