예제 #1
0
func TestTraverse(t *testing.T) {
	const (
		ε = 1e-14
	)

	test := func(points, Δ []float64, steps []uint) {
		a, b := traverse(points, ε)
		assert.Equal(a, Δ, t)
		assert.Equal(b, steps, t)
	}

	test(
		[]float64{0, 1, 2, 3, 4, 1, 2, 3, 4, 5},
		[]float64{1, 1, 1, 1, 1},
		[]uint{0, 1, 2, 3, 4, 1, 2, 3, 4, 5},
	)

	test(
		[]float64{0, 0, 0, 2, 4, 0, 6, 8},
		[]float64{2, 2, 2, 2},
		[]uint{0, 0, 0, 1, 2, 0, 3, 4},
	)

	test(
		[]float64{15, 10, 6, 3, 3, 1},
		[]float64{2, 3, 4, 5},
		[]uint{4, 3, 2, 1, 1, 0},
	)
}
예제 #2
0
func TestNew(t *testing.T) {
	config, _ := New("fixtures/004_040.json")

	assert.Equal(config.System.Floorplan, "fixtures/004.flp", t)
	assert.Equal(config.System.Configuration, "fixtures/hotspot.config", t)
	assert.Equal(config.System.Specification, "fixtures/004_040.tgff", t)
}
예제 #3
0
func TestUniqueRewrite(t *testing.T) {
	unique := NewUnique(2)

	index := []uint64{4, 2}
	assert.Equal(unique.Distil(index), []uint64{4, 2}, t)

	index[0], index[1] = 6, 9
	assert.Equal(unique.Distil([]uint64{4, 2}), []uint64{}, t)
}
예제 #4
0
func TestStep(t *testing.T) {
	fixture := &fixtureStep
	algorithm, strategy := prepare(fixture)

	surrogate := algorithm.Compute(fixture.target, strategy)
	assert.Equal(surrogate, fixture.surrogate, t)

	values := algorithm.Evaluate(surrogate, fixture.points)
	assert.Equal(values, fixture.values, t)
}
예제 #5
0
func TestSample(t *testing.T) {
	const (
		Δt = 1e-3
	)

	power, schedule := prepare("002_040")

	assert.Equal(power.Sample(schedule, Δt, 440), fixtureSample.P, t)
	assert.Equal(power.Sample(schedule, Δt, 42), fixtureSample.P[:2*42], t)
}
예제 #6
0
func TestListDelayDummy(t *testing.T) {
	platform, application, _ := system.Load(findFixture("002_040"))
	profile := system.NewProfile(platform, application)

	list := NewList(platform, application)
	schedule1 := list.Compute(profile.Mobility)
	schedule2 := list.Delay(schedule1, make([]float64, len(schedule1.Start)))

	assert.Equal(schedule2.Start, schedule1.Start, t)
	assert.Equal(schedule2.Finish, schedule1.Finish, t)
}
예제 #7
0
func TestBranin(t *testing.T) {
	fixture := &fixtureBranin
	algorithm, strategy := prepare(fixture)

	surrogate := algorithm.Compute(fixture.target, strategy)
	assert.Equal(surrogate.Nodes, fixture.surrogate.Nodes, t)
	assert.Equal(interpolation.Validate(surrogate.Indices, surrogate.Inputs,
		fixture.grid), true, t)

	values := algorithm.Evaluate(surrogate, fixture.points)
	assert.EqualWithin(values, fixture.values, 0.1, t)
}
예제 #8
0
func TestKraichnanOrszag(t *testing.T) {
	fixture := &fixtureKraichnanOrszag
	algorithm, strategy := prepare(fixture)

	surrogate := algorithm.Compute(fixture.target, strategy)
	assert.Equal(surrogate.Nodes, fixture.surrogate.Nodes, t)
	assert.EqualWithin(surrogate.Integral, fixture.surrogate.Integral, 2e-14, t)
	assert.Equal(interpolation.Validate(surrogate.Indices, surrogate.Inputs,
		fixture.grid), true, t)

	values := algorithm.Evaluate(surrogate, fixture.points)
	assert.EqualWithin(values, fixture.values, 6e-14, t)
}
예제 #9
0
func TestListCompute(t *testing.T) {
	platform, application, _ := system.Load(findFixture("002_040"))
	profile := system.NewProfile(platform, application)

	list := NewList(platform, application)
	schedule := list.Compute(profile.Mobility)

	mapping := []uint{
		0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0,
		1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0,
	}

	order := []uint{
		0, 1, 2, 4, 7, 8, 5, 11, 3, 9, 15, 19, 20, 10, 12, 24, 30, 17, 22, 28, 29,
		18, 21, 27, 34, 26, 13, 16, 23, 31, 33, 25, 38, 39, 37, 35, 14, 36, 6, 32,
	}

	start := []float64{
		0.0000, 0.0230, 0.0350, 0.0910, 0.0470, 0.0790, 0.4220, 0.0680,
		0.0680, 0.1030, 0.1530, 0.0900, 0.1720, 0.3150, 0.4040, 0.1170,
		0.3360, 0.2040, 0.2590, 0.1380, 0.1530, 0.2720, 0.2190, 0.3360,
		0.1850, 0.3640, 0.3040, 0.2920, 0.2340, 0.2590, 0.2040, 0.3510,
		0.4250, 0.3510, 0.3040, 0.4000, 0.4150, 0.3880, 0.3770, 0.3880,
	}

	duration := []float64{
		0.0230, 0.0120, 0.0120, 0.0120, 0.0210, 0.0110, 0.0180, 0.0230,
		0.0110, 0.0140, 0.0190, 0.0150, 0.0130, 0.0210, 0.0110, 0.0210,
		0.0150, 0.0150, 0.0130, 0.0150, 0.0210, 0.0200, 0.0150, 0.0100,
		0.0190, 0.0130, 0.0110, 0.0120, 0.0250, 0.0150, 0.0180, 0.0190,
		0.0140, 0.0130, 0.0260, 0.0220, 0.0100, 0.0160, 0.0110, 0.0120,
	}

	finish := make([]float64, len(start))
	span := 0.0
	for i := range start {
		finish[i] = start[i] + duration[i]
		if span < finish[i] {
			span = finish[i]
		}
	}

	assert.Equal(schedule.Cores, uint(2), t)
	assert.Equal(schedule.Tasks, uint(40), t)
	assert.EqualWithin(schedule.Span, span, 1e-15, t)

	assert.Equal(schedule.Mapping, mapping, t)
	assert.Equal(schedule.Order, order, t)
	assert.EqualWithin(schedule.Start, start, 1e-15, t)
	assert.EqualWithin(schedule.Finish, finish, 1e-15, t)
}
예제 #10
0
func TestUniqueMapping(t *testing.T) {
	unique := NewUnique(2)

	assert.Equal(unique.Distil([]uint64{4, 2}), []uint64{4, 2}, t)
	assert.Equal(unique.Distil([]uint64{6, 9}), []uint64{6, 9}, t)
	assert.Equal(unique.Distil([]uint64{4, 2}), []uint64{}, t)

	keys := make([]string, 0)
	for k, _ := range unique.mapping {
		keys = append(keys, k)
	}
	sort.Sort(sort.StringSlice(keys))

	assert.Equal(len(keys), 2, t)

	if isLittleEndian() {
		assert.Equal(keys[0],
			"\x04\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", t)
		assert.Equal(keys[1],
			"\x06\x00\x00\x00\x00\x00\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00", t)
	} else {
		assert.Equal(keys[0],
			"\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x02", t)
		assert.Equal(keys[1],
			"\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x09", t)
	}
}
예제 #11
0
func TestOpenParent(t *testing.T) {
	grid := NewOpen(1)

	childLevels := []uint64{1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3}
	childOrders := []uint64{0, 2, 0, 2, 4, 6, 0, 2, 4, 6, 8, 10, 12, 14}

	parentLevels := []uint64{0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2}
	parentOrders := []uint64{0, 0, 0, 0, 2, 2, 0, 0, 2, 2, 4, 4, 6, 6}

	for i := range childLevels {
		level, order := grid.Parent(childLevels[i], childOrders[i])
		assert.Equal(level, parentLevels[i], t)
		assert.Equal(order, parentOrders[i], t)
	}
}
예제 #12
0
func TestClosedParent(t *testing.T) {
	grid := NewClosed(1)

	childLevels := []uint64{1, 1, 2, 2, 3, 3, 3, 3}
	childOrders := []uint64{0, 2, 1, 3, 1, 3, 5, 7}

	parentLevels := []uint64{0, 0, 1, 1, 2, 2, 2, 2}
	parentOrders := []uint64{0, 0, 0, 2, 1, 1, 3, 3}

	for i := range childLevels {
		level, order := grid.Parent(childLevels[i], childOrders[i])
		assert.Equal(level, parentLevels[i], t)
		assert.Equal(order, parentOrders[i], t)
	}
}
예제 #13
0
func TestDetect(t *testing.T) {
	data1 := []float64{1, math.Inf(1), 2, 0}
	data2 := []float64{0, 2, 4, 1, 1, 1, 4}
	edges := []float64{math.Inf(-1), 0, 1, 2, 4, math.Inf(1)}

	assert.Equal(detect(data1, data2), edges, t)
}
예제 #14
0
func TestSolutionCompute(t *testing.T) {
	config, _ := config.New("fixtures/002_020.json")
	system, _ := system.New(&config.System)
	uncertainty, _ := uncertainty.NewEpistemic(system, &config.Uncertainty)

	quantity, _ := quantity.New(system, uncertainty, &config.Quantity)
	ni, no := quantity.Dimensions()

	solution, _ := New(ni, no, &config.Solution)
	surrogate := solution.Compute(quantity, quantity)

	nn := surrogate.Surrogate.Nodes

	assert.Equal(nn, uint(841), t)

	grid := grid.NewClosed(ni)
	nodes := grid.Compute(surrogate.Surrogate.Indices)

	values := make([]float64, nn*no)
	for i := uint(0); i < nn; i++ {
		quantity.Compute(nodes[i*ni:(i+1)*ni], values[i*no:(i+1)*no])
	}

	assert.EqualWithin(values, solution.Evaluate(surrogate, nodes), 1e-15, t)
}
예제 #15
0
func TestGrid(t *testing.T) {
	product := newGrid(3, 4*3*2)

	product.next([]float64{1, 2, 3, 4})
	product.next([]float64{10, 20, 30})
	product.next([]float64{100, 200})

	assert.Equal(product.values, []float64{
		1, 10, 100,
		2, 10, 100,
		3, 10, 100,
		4, 10, 100,
		1, 20, 100,
		2, 20, 100,
		3, 20, 100,
		4, 20, 100,
		1, 30, 100,
		2, 30, 100,
		3, 30, 100,
		4, 30, 100,
		1, 10, 200,
		2, 10, 200,
		3, 10, 200,
		4, 10, 200,
		1, 20, 200,
		2, 20, 200,
		3, 20, 200,
		4, 20, 200,
		1, 30, 200,
		2, 30, 200,
		3, 30, 200,
		4, 30, 200,
	}, t)
}
예제 #16
0
func TestWeight(t *testing.T) {
	product := newWeight(4 * 3 * 2)

	product.next([]float64{1, 2, 3, 4})
	product.next([]float64{10, 20, 30})
	product.next([]float64{100, 200})

	assert.Equal(product.values, []float64{
		1 * 10 * 100,
		2 * 10 * 100,
		3 * 10 * 100,
		4 * 10 * 100,
		1 * 20 * 100,
		2 * 20 * 100,
		3 * 20 * 100,
		4 * 20 * 100,
		1 * 30 * 100,
		2 * 30 * 100,
		3 * 30 * 100,
		4 * 30 * 100,
		1 * 10 * 200,
		2 * 10 * 200,
		3 * 10 * 200,
		4 * 10 * 200,
		1 * 20 * 200,
		2 * 20 * 200,
		3 * 20 * 200,
		4 * 20 * 200,
		1 * 30 * 200,
		2 * 30 * 200,
		3 * 30 * 200,
		4 * 30 * 200,
	}, t)
}
예제 #17
0
func TestClosedCompute1D1P(t *testing.T) {
	basis := NewClosed(1, 1)

	compute := func(level, order uint64, point float64) float64 {
		return basis.Compute(internal.Compose([]uint64{level}, []uint64{order}), []float64{point})
	}

	points := []float64{0.0, 0.25, 0.5, 0.75, 1.0}

	cases := []struct {
		level  uint64
		order  uint64
		values []float64
	}{
		{0, 0, []float64{1.0, 1.0, 1.0, 1.0, 1.0}},
		{1, 0, []float64{1.0, 0.5, 0.0, 0.0, 0.0}},
		{1, 2, []float64{0.0, 0.0, 0.0, 0.5, 1.0}},
		{2, 1, []float64{0.0, 1.0, 0.0, 0.0, 0.0}},
		{2, 3, []float64{0.0, 0.0, 0.0, 1.0, 0.0}},
	}

	values := make([]float64, len(points))

	for i := range cases {
		for j := range values {
			values[j] = compute(cases[i].level, cases[i].order, points[j])
		}
		assert.Equal(values, cases[i].values, t)
	}
}
예제 #18
0
func TestKolmogorovSmirnovGaussian(t *testing.T) {
	data1 := []float64{
		+1.8368909586194213e-01, -4.7615301661907383e-01,
		+8.6202161155692203e-01, -1.3616944708707543e+00,
		+4.5502955644433435e-01, -8.4870937993365902e-01,
		-3.3488693896404770e-01, +5.5278334594455014e-01,
		+1.0390906535049560e+00, -1.1176386832652081e+00,
		+1.2606587091208963e+00, +6.6014314104697769e-01,
		-6.7865553542687335e-02, -1.9522119789875436e-01,
		-2.1760635014319193e-01, -3.0310762135174091e-01,
		+2.3045624425105282e-02, +5.1290355848774699e-02,
		+8.2606279021159545e-01, +1.5269766867333727e+00,
	}

	data2 := []float64{
		+4.6691443568470004e-01, -2.0971333838873671e-01,
		+6.2519035708762571e-01, +1.8322726300143696e-01,
		-1.0297675435666211e+00, +9.4922183113102254e-01,
		+3.0706191914670344e-01, +1.3517494209945566e-01,
		+5.1524633552484855e-01, +2.6140632405538267e-01,
		-9.4148577095543373e-01, -1.6233767280382774e-01,
		-1.4605463433152618e-01, -5.3201137680882071e-01,
		+1.6821035946631788e+00, -8.7572934616001730e-01,
		-4.8381505011012110e-01, -7.1200454902742250e-01,
		-1.1742123314568162e+00, -1.9223951753927476e-01,
	}

	rejected, pvalue, statistic := KolmogorovSmirnov(data1, data2, 0.05)

	assert.Equal(rejected, false, t)
	assert.EqualWithin(pvalue, 7.7095294467658659e-01, 1e-15, t)
	assert.EqualWithin(statistic, 2.0000000000000007e-01, 1e-15, t)
}
예제 #19
0
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)
	}
}
예제 #20
0
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)
	}
}
예제 #21
0
func TestEdges(t *testing.T) {
	data1 := []float64{1.0, infinity, 2.0, 0.0}
	data2 := []float64{0.0, 2.0, 4.0, 1.0, 1.0, 1.0, 4.0}
	edges := []float64{-infinity, 0.0, 1.0, 2.0, 4.0, infinity}

	assert.Equal(Edges(data1, data2), edges, t)
}
예제 #22
0
func TestClosedIndex1D(t *testing.T) {
	cases := []struct {
		level  uint64
		levels []uint64
		orders []uint64
	}{
		{
			level:  0,
			levels: []uint64{0},
			orders: []uint64{0},
		},
		{
			level:  1,
			levels: []uint64{1, 1},
			orders: []uint64{0, 2},
		},
		{
			level:  2,
			levels: []uint64{2, 2},
			orders: []uint64{1, 3},
		},
		{
			level:  3,
			levels: []uint64{3, 3, 3, 3},
			orders: []uint64{1, 3, 5, 7},
		},
	}

	for _, c := range cases {
		assert.Equal(closedIndex(c.level), internal.Compose(c.levels, c.orders), t)
	}
}
예제 #23
0
func TestClosedCompute1D(t *testing.T) {
	grid := NewClosed(1)

	levels := []uint64{0, 1, 1, 2, 2, 3, 3, 3, 3}
	orders := []uint64{0, 0, 2, 1, 3, 1, 3, 5, 7}
	nodes := []float64{0.5, 0.0, 1.0, 0.25, 0.75, 0.125, 0.375, 0.625, 0.875}

	assert.Equal(grid.Compute(internal.Compose(levels, orders)), nodes, t)
}
예제 #24
0
func TestMultiplyAdd(t *testing.T) {
	m := uint(2)
	p := uint(3)
	n := uint(4)

	a := []float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0}
	b := []float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0}
	c := []float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0}
	d := make([]float64, m*n)

	MultiplyAdd(a, b, c, d, m, p, n)

	assert.Equal(d, []float64{23.0, 30.0, 52.0, 68.0, 81.0, 106.0, 110.0, 144.0}, t)
	assert.Equal(c, []float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0}, t)

	MultiplyAdd(a, b, c, c, m, p, n)

	assert.Equal(c, []float64{23.0, 30.0, 52.0, 68.0, 81.0, 106.0, 110.0, 144.0}, t)
}
예제 #25
0
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)
}
예제 #26
0
func TestClosedIntegrate(t *testing.T) {
	basis := NewClosed(1, 1)

	levels := []uint64{0, 1, 2, 3}
	values := []float64{1.0, 0.25, 1.0 / 2.0 / 2.0, 1.0 / 2.0 / 2.0 / 2.0}

	for i := range levels {
		indices := internal.Compose([]uint64{levels[i]}, []uint64{0})
		assert.Equal(basis.Integrate(indices), values[i], t)
	}
}
예제 #27
0
func TestClosedCompute2D(t *testing.T) {
	grid := NewClosed(2)

	levels := []uint64{
		0, 0,
		0, 1,
		0, 1,
		1, 0,
		1, 0,
		0, 2,
		0, 2,
		1, 1,
		1, 1,
		1, 1,
		1, 1,
		2, 0,
		2, 0,
	}

	orders := []uint64{
		0, 0,
		0, 0,
		0, 2,
		0, 0,
		2, 0,
		0, 1,
		0, 3,
		0, 0,
		0, 2,
		2, 0,
		2, 2,
		1, 0,
		3, 0,
	}

	nodes := []float64{
		0.50, 0.50,
		0.50, 0.00,
		0.50, 1.00,
		0.00, 0.50,
		1.00, 0.50,
		0.50, 0.25,
		0.50, 0.75,
		0.00, 0.00,
		0.00, 1.00,
		1.00, 0.00,
		1.00, 1.00,
		0.25, 0.50,
		0.75, 0.50,
	}

	assert.Equal(grid.Compute(internal.Compose(levels, orders)), nodes, t)
}
예제 #28
0
func TestClosedRefine1D(t *testing.T) {
	grid := NewClosed(1)

	levels := []uint64{0, 1, 1, 2, 2, 3, 3, 3, 3}
	orders := []uint64{0, 0, 2, 1, 3, 1, 3, 5, 7}
	childLevels := []uint64{1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4}
	childOrders := []uint64{0, 2, 1, 3, 1, 3, 5, 7, 1, 3, 5, 7, 9, 11, 13, 15}

	indices := grid.Refine(internal.Compose(levels, orders))

	assert.Equal(indices, internal.Compose(childLevels, childOrders), t)
}
예제 #29
0
func TestPartition(t *testing.T) {
	const (
		n = 10
		ε = 1e-14
	)

	power, schedule := prepare("002_040")
	P, ΔT := power.Partition(schedule, ε)

	assert.Equal(P, fixturePartition.P, t)
	assert.EqualWithin(ΔT, fixturePartition.ΔT, 1e-15, t)
}
예제 #30
0
func TestInverse(t *testing.T) {
	m := uint(3)

	A := []float64{
		1.0, 2.0, 3.0,
		2.0, 4.0, 5.0,
		3.0, 5.0, 6.0,
	}
	U := make([]float64, m*m)
	Λ := make([]float64, m)

	err := decomposition.SymmetricEigen(A, U, Λ, m)
	assert.Equal(err, nil, t)

	err = matrix.Invert(A, m)
	assert.Equal(err, nil, t)

	I, err := invert(U, Λ, m)
	assert.Equal(err, nil, t)
	assert.EqualWithin(A, I, 1e-14, t)
}