github.com/fluhus/gostuff@v0.4.1-0.20240331134726-be71864f2b5d/gnum/vecs_test.go (about)

     1  package gnum
     2  
     3  import (
     4  	"slices"
     5  	"testing"
     6  )
     7  
     8  func TestOnes(t *testing.T) {
     9  	want := []int8{1, 1, 1, 1}
    10  	got := Ones[[]int8](4)
    11  	if !slices.Equal(got, want) {
    12  		t.Errorf("Ones(4) = %v, want %v", got, want)
    13  	}
    14  }
    15  
    16  func TestAdd(t *testing.T) {
    17  	a := []uint{4, 6}
    18  	b := []uint{2, 3}
    19  	got := Add(nil, a, b)
    20  	want := []uint{6, 9}
    21  	if !slices.Equal(got, want) {
    22  		t.Errorf("Add(nil, %v, %v)=%v, want %v", a, b, got, want)
    23  	}
    24  	if want := []uint{4, 6}; !slices.Equal(a, want) {
    25  		t.Errorf("a=%v, want %v", a, want)
    26  	}
    27  	if want := []uint{2, 3}; !slices.Equal(b, want) {
    28  		t.Errorf("b=%v, want %v", b, want)
    29  	}
    30  }
    31  
    32  func TestAdd_inplace(t *testing.T) {
    33  	a := []uint{4, 6}
    34  	b := []uint{2, 3}
    35  	got := Add(a, b)
    36  	want := []uint{6, 9}
    37  	if !slices.Equal(got, want) {
    38  		t.Errorf("Add(nil, %v, %v)=%v, want %v", a, b, got, want)
    39  	}
    40  	if !slices.Equal(a, want) {
    41  		t.Errorf("a=%v, want %v", a, want)
    42  	}
    43  	if want := []uint{2, 3}; !slices.Equal(b, want) {
    44  		t.Errorf("b=%v, want %v", b, want)
    45  	}
    46  }