File: generate_test.go

package info (click to toggle)
golang-github-kshedden-dstream 0.0~git20190512.c4c4106-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 596 kB
  • sloc: makefile: 30
file content (58 lines) | stat: -rw-r--r-- 949 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package dstream

import "testing"

func TestGenerate1(t *testing.T) {

	x := [][]interface{}{
		{
			[]float64{0, 0, 0},
			[]float64{1, 1, 1},
			[]float64{2, 2, 3},
		},
		{
			[]float64{0, 0, 1},
			[]float64{1, 2, 2},
			[]float64{3, 3, 3},
		},
		{
			[]float64{1, 2, 3},
			[]float64{4, 5, 6},
			[]float64{7, 8, 9},
		},
		{
			[]string{"a", "b", "c"},
			[]string{"d", "e", "f"},
			[]string{"g", "h", "i"},
		},
	}

	na := []string{"x1", "x2", "x3", "x4"}
	da := NewFromArrays(x, na)

	x = append(x,
		[]interface{}{
			[]float64{0, 0, 0},
			[]float64{1, 2, 2},
			[]float64{6, 6, 9},
		})
	na = []string{"x1", "x2", "x3", "x4", "x5"}
	ex := NewFromArrays(x, na)

	f := func(v map[string]interface{}, x interface{}) {
		z := x.([]float64)

		x1 := v["x1"].([]float64)
		x2 := v["x2"].([]float64)

		for i := range x1 {
			z[i] = x1[i] * x2[i]
		}
	}

	db := Generate(da, "x5", f, Float64)

	if !EqualReport(db, ex, true) {
		t.Fail()
	}
}