blob: 2548478a56c2652b62b611612eb7f3a3e3b898e2 [file] [log] [blame]
// Copyright 2016 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package math_test
import (
"testing"
"v.io/v23/vom"
)
func TestComplex64EncodeDecode(t *testing.T) {
cplxIn := complex64(-1 - 3i)
data, err := vom.Encode(cplxIn)
if err != nil {
t.Fatalf("error encoding %T: %v", cplxIn, err)
}
var out interface{}
if err := vom.Decode(data, &out); err != nil {
t.Fatalf("error decoding %T: %v", cplxIn, err)
}
if cplxOut, ok := out.(complex64); ok {
if got, want := cplxOut, cplxIn; got != want {
t.Errorf("got %v, want %v", got, want)
}
} else {
t.Fatalf("incorrect output type: got %T, want %T", out, cplxIn)
}
}
func TestComplex128EncodeDecode(t *testing.T) {
cplxIn := complex128(-1 - 3i)
data, err := vom.Encode(cplxIn)
if err != nil {
t.Fatalf("error encoding %T: %v", cplxIn, err)
}
var out interface{}
if err := vom.Decode(data, &out); err != nil {
t.Fatalf("error decoding %T: %v", cplxIn, err)
}
if cplxOut, ok := out.(complex128); ok {
if got, want := cplxOut, cplxIn; got != want {
t.Errorf("got %v, want %v", got, want)
}
} else {
t.Fatalf("incorrect output type: got %T, want %T", out, cplxIn)
}
}