func TestPutTwice(t *testing.T) { path := fixture.MakeFile() defer os.Remove(path) file, err := Create(path) assert.Success(err, t) defer file.Close() assert.Success(file.Put("A", 42), t) assert.Success(file.Put("A", 42), t) }
func TestParseNaturalIndex(t *testing.T) { cases := []struct { line string min uint max uint result []uint }{ {"", 0, 10, nil}, {"[]", 0, 10, []uint{}}, {"[0, 1, 11]", 0, 10, nil}, {"[0, 1, 9, 10]", 0, 10, []uint{0, 1, 9, 10}}, {"[0:10]", 0, 10, []uint{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}, {"[1:2:10]", 0, 10, []uint{1, 3, 5, 7, 9}}, {"[0:2:10]", 0, 10, []uint{0, 2, 4, 6, 8, 10}}, {"[0:5:15]", 0, 10, nil}, {"[0, 1, end]", 0, 10, []uint{0, 1, 10}}, {"[0:2:end]", 0, 10, []uint{0, 2, 4, 6, 8, 10}}, {"[0:end]", 0, 10, []uint{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}, } for _, c := range cases { result, err := ParseNaturalIndex(c.line, c.min, c.max) if c.result != nil { assert.Success(err, t) } assert.Equal(result, c.result, t) } }
func TestParseRealIndex(t *testing.T) { cases := []struct { line string min float64 max float64 result []float64 }{ {"", 0, 1, nil}, {"[]", 0, 1, []float64{}}, {"[0, 0.1, 0.9, 1]", 0, 1, []float64{0.0, 0.1, 0.9, 1.0}}, {"[0, 0.1, 1.1]", 0, 1, nil}, {"[0:1]", 0, 1, []float64{0, 1}}, {"[0.1:0.2:1]", 0, 1, []float64{0.1, 0.3, 0.5, 0.7, 0.9}}, {"[0:0.2:1]", 0, 1, []float64{0.0, 0.2, 0.4, 0.6, 0.8, 1.0}}, {"[0:0.5:1.5]", 0, 1, nil}, {"[0, 0.2, end]", 0, 1, []float64{0.0, 0.2, 1.0}}, {"[0:0.2:end]", 0, 1, []float64{0.0, 0.2, 0.4, 0.6, 0.8, 1.0}}, {"[0:end]", 0, 1, []float64{0, 1}}, } for _, c := range cases { result, err := ParseRealIndex(c.line, c.min, c.max) if c.result != nil { assert.Success(err, t) } assert.EqualWithin(result, c.result, 1e-15, t) } }
func TestParse(t *testing.T) { cases := []struct { line string success bool }{ {"Beta(1, 1)", true}, {"beta(0.5, 1.5)", true}, {" Beta \t (1, 1)", true}, {"Gamma(1, 1)", false}, {"Beta(1, 1, 1)", false}, {"beta(-1, 1)", false}, {"beta(0, 1)", false}, {"beta(1, -1)", false}, {"beta(1, 0)", false}, {"beta(1, 0)", false}, {"uniform()", true}, {"uniform( )", true}, } for _, c := range cases { if _, err := Parse(c.line); c.success { assert.Success(err, t) } else { assert.Failure(err, t) } } }
func TestExtractTaskNumber(t *testing.T) { scenarios := []struct { name string total uint result uint success bool }{ {"t0_0", 50, 0, true}, {"t0_42", 50, 42, true}, {"t0_42", 43, 42, true}, {"t0_42", 42, 0, false}, {"t1_42", 50, 0, false}, {"t0_-2", 50, 0, false}, } for _, s := range scenarios { result, err := extractTaskID(s.name, s.total) if s.success { assert.Success(err, t) } else { assert.Failure(err, t) } assert.Equal(result, s.result, t) } }
func TestCorrelateLarge(t *testing.T) { _, application, _ := system.Load("fixtures/016_160.tgff") ε := math.Sqrt(math.Nextafter(1.0, 2.0) - 1.0) R := Compute(application, index(160), 5) _, _, err := decomposition.CovPCA(R, 160, ε) assert.Success(err, t) }
func TestCorrelateSmall(t *testing.T) { _, application, _ := system.Load("fixtures/002_020.tgff") R := Compute(application, index(20), 2) _, _, err := decomposition.CovPCA(R, 20, 0) assert.Success(err, t) R = Compute(application, index(1), 2) assert.Equal(R, []float64{1.0}, t) }
func TestPut(t *testing.T) { path := fixture.MakeFile() defer os.Remove(path) file, _ := Open(path, "w7.3") defer file.Close() for i, o := range fixtureObjects { assert.Success(file.Put(fmt.Sprintf("%c", 'A'+i), o), t) } }
func TestPutMatrix(t *testing.T) { path := fixture.MakeFile() defer os.Remove(path) file, _ := Open(path, "w7.3") defer file.Close() name, rows, cols := "a", uint(2), uint(3) data := []float64{1, 2, 3, 4, 5, 6} assert.Success(file.PutMatrix(name, data, rows, cols), t) }
func TestGet(t *testing.T) { path := findFixture("data.mat") file, _ := Open(path, "r") defer file.Close() for i, o := range fixtureObjects { v := reflect.New(reflect.TypeOf(o)) p := v.Interface() assert.Success(file.Get(fmt.Sprintf("%c", 'A'+i), p), t) assert.Equal(reflect.Indirect(v).Interface(), o, t) } }
func TestPutGet(t *testing.T) { path := fixture.MakeFile() defer os.Remove(path) file, err := Create(path) assert.Success(err, t) for i, o := range fixtureObjects { assert.Success(file.Put(fmt.Sprintf("%c", 'A'+i), o), t) } assert.Success(file.Close(), t) file, err = Open(path) assert.Success(err, t) for i, o := range fixtureObjects { v := reflect.New(reflect.TypeOf(o)) p := v.Interface() assert.Success(file.Get(fmt.Sprintf("%c", 'A'+i), p), t) assert.Equal(reflect.Indirect(v).Interface(), o, t) } assert.Success(file.Close(), t) }
func TestPutGetWithDimensions(t *testing.T) { path := fixture.MakeFile() defer os.Remove(path) data1 := []float64{ 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.20, 0.21, 0.22, 0.23, 0.24, } file, err := Create(path) assert.Success(err, t) assert.Success(file.Put("data", data1, 2, 3, 4), t) assert.Success(file.Close(), t) data2 := []float64{} file, err = Open(path) assert.Success(err, t) assert.Success(file.Get("data", &data2), t) assert.Success(file.Close(), t) assert.Equal(data1, data2, t) }
func TestCovPCA(t *testing.T) { Σ := []float64{ +1.000000000000000e+00, +1.154127058177033e-01, +3.134709671301593e-01, -2.624605475789556e-01, -2.675628902376415e-01, +1.154127058177033e-01, +1.000000000000000e+00, +1.487775664601468e-01, +8.251722261621278e-01, +6.471493243665016e-01, +3.134709671301593e-01, +1.487775664601468e-01, +1.000000000000000e+00, +2.188948568766876e-01, -4.746506616202846e-01, -2.624605475789556e-01, +8.251722261621278e-01, +2.188948568766876e-01, +1.000000000000000e+00, +7.047860759340304e-01, -2.675628902376415e-01, +6.471493243665017e-01, -4.746506616202846e-01, +7.047860759340304e-01, +1.000000000000000e+00, } expectedU := []float64{ -1.777008675251867e-01, +5.456098595844089e-01, -7.679302728419535e-02, +5.862167305996994e-01, +5.667319106337718e-01, +5.274851240801810e-01, +3.209998200695767e-01, +7.174077977724287e-01, +1.998699259327777e-01, -2.531731103264220e-01, +7.655128668903998e-01, +1.936393917712877e-01, -4.774829578033630e-01, -2.733383132570983e-01, +2.716431999752671e-01, -2.541030814371850e-01, +7.277625876615521e-01, -2.402296315689612e-01, -2.880993167658167e-01, -5.148609014089138e-01, +1.990063320205669e-01, -1.792607000828338e-01, -4.401461482047020e-01, +6.772642819885449e-01, -5.252109497950679e-01, } expectedΛ := []float64{ 2.500258665819985e+00, 1.525542276483301e+00, 8.324395052148045e-01, 1.261010747114109e-01, 1.565847777049709e-02, } U, Λ, err := CovPCA(Σ, 5, 0.0) assert.Success(err, t) assert.EqualWithin(Λ, expectedΛ, 1e-14, t) assert.EqualWithin(abs(U), abs(expectedU), 1e-14, t) }
func TestLoadTGFF(t *testing.T) { platform, application, err := loadTGFF(findFixture("002_040")) assert.Success(err, t) assert.Equal(len(platform.Cores), 2, t) assert.Equal(len(application.Tasks), 40, t) tasks := []struct { children []uint }{ {[]uint{1}}, {[]uint{2, 3, 23, 32}}, {[]uint{4, 10, 11, 12}}, {[]uint{9, 10, 26}}, {[]uint{5, 6, 7, 8}}, {[]uint{10, 11, 27}}, {nil}, {[]uint{9}}, {[]uint{9}}, {[]uint{13, 14, 15}}, {[]uint{12}}, {[]uint{12, 31}}, {[]uint{17, 18, 24}}, {[]uint{16, 25}}, {[]uint{36}}, {[]uint{19, 20, 23, 29}}, {[]uint{31}}, {[]uint{22, 35}}, {[]uint{21, 23}}, {[]uint{20, 24}}, {[]uint{24, 26}}, {[]uint{27}}, {[]uint{28, 29}}, {[]uint{31}}, {[]uint{30}}, {[]uint{37, 38}}, {nil}, {[]uint{33, 34}}, {[]uint{29}}, {nil}, {nil}, {[]uint{36}}, {nil}, {nil}, {nil}, {nil}, {nil}, {nil}, {[]uint{39}}, {nil}, } for i, task := range tasks { assert.Equal(application.Tasks[i].Children, task.children, t) } }