Example #1
0
func TestReaderShouldReadFloatSliceWithTowValues(t *testing.T) {
	assert := assert.New(t)
	reader := strings.NewReader("4 5")
	read, _ := Read(reader)
	assert.That(read[0]).IsEqualTo(float64(4))
	assert.That(read[1]).IsEqualTo(float64(5))
}
Example #2
0
func TestNormalizerShouldNormalizeDifferentElements(t *testing.T) {
	assert := assert.New(t)
	slice := []float64{3, 6}
	normalized := Normalize(slice)
	assert.That(normalized[0]).IsEqualTo(float64(0.5))
	assert.That(normalized[1]).IsEqualTo(float64(1))
}
Example #3
0
func TestSumShouldSumWithSNRAndMaxAmplitudeOfSignal(t *testing.T) {
	assert := assert.New(t)
	first := []float64{2}
	second := []float64{-6}
	sum := AddSignalToNoise(first, second, 20)
	assert.That((sum[0]-2)*(sum[0]-2) < 0.4000001).IsEqualTo(true)
	assert.That((sum[0]-2)*(sum[0]-2) > 0.3999999).IsEqualTo(true)
}
Example #4
0
func TestSumShouldSumWithSNR(t *testing.T) {
	assert := assert.New(t)
	first := []float64{1}
	second := []float64{1}
	sum := AddSignalToNoise(first, second, 20)
	assert.That((sum[0]-1)*(sum[0]-1) < 0.1000001).IsEqualTo(true)
	assert.That((sum[0]-1)*(sum[0]-1) > 0.0999999).IsEqualTo(true)
}
Example #5
0
func TestNormalizerShouldNormalizeWithNegativeElements(t *testing.T) {
	assert := assert.New(t)
	slice := []float64{3, 6, -12}
	normalized := Normalize(slice)
	assert.That(normalized[0]).IsEqualTo(float64(0.25))
	assert.That(normalized[1]).IsEqualTo(float64(0.5))
	assert.That(normalized[2]).IsEqualTo(float64(-1))
}
Example #6
0
func TestSumShouldSum(t *testing.T) {
	assert := assert.New(t)
	first := []float64{0.5, 1, -1}
	second := []float64{-0.5, -1, 1}
	sum := AddSignalToNoise(first, second, 0)
	assert.That(sum[0]).IsEqualTo(float64(0))
	assert.That(sum[1]).IsEqualTo(float64(0))
	assert.That(sum[2]).IsEqualTo(float64(0))
}
Example #7
0
func TestCountCorrectColorAndPosition(t *testing.T) {
	assert := assert.New(t)

	noPegIsCorrectPositionOrColor := CountCorrectColorAndPosition([...]string{"B", "B", "B", "B"}, [...]string{"N", "N", "N", "N"})
	assert.That(noPegIsCorrectPositionOrColor).IsEqualTo(0)

	onePegIsCorrectPositionAndColor := CountCorrectColorAndPosition([...]string{"B", "B", "B", "B"}, [...]string{"B", "N", "N", "N"})
	assert.That(onePegIsCorrectPositionAndColor).IsEqualTo(1)

	allPegsAreCorrectPositionAndColor := CountCorrectColorAndPosition([...]string{"B", "B", "B", "B"}, [...]string{"B", "B", "B", "B"})
	assert.That(allPegsAreCorrectPositionAndColor).IsEqualTo(4)
}
Example #8
0
func TestFooBarQix(t *testing.T) {
	assert := assert.New(t)

	assert.That(foobarqix(1)).IsEqualTo("1")
	assert.That(foobarqix(2)).IsEqualTo("2")
	assert.That(foobarqix(3)).IsEqualTo("FooFoo")
	assert.That(foobarqix(5)).IsEqualTo("BarBar")
	assert.That(foobarqix(7)).IsEqualTo("QixQix")
	assert.That(foobarqix(9)).IsEqualTo("Foo")
	assert.That(foobarqix(10)).IsEqualTo("Bar")
	assert.That(foobarqix(14)).IsEqualTo("Qix")
	assert.That(foobarqix(15)).IsEqualTo("FooBarBar")
}
Example #9
0
func TestAlgorithmShouldRun(t *testing.T) {
	assert := assert.New(t)
	reader := strings.NewReader("1 1 1 1")
	noise := arrayBasedRandomProvider([]float64{1, 1, 1, 1})
	writer := bytes.Buffer{}
	Algorithm(reader, &writer, 0, noise)
	assert.That(writer.String()).IsEqualTo("2 2 2 2\n")
}
Example #10
0
func TestCountCorrectColorWrongPosition(t *testing.T) {
	assert := assert.New(t)

	noPegIsCorrectColor := CountCorrectColorWrongPosition([...]string{"B", "B", "B", "B"}, [...]string{"N", "N", "N", "N"})
	assert.That(noPegIsCorrectColor).IsEqualTo(0)

	onePegIsCorrectColorAndWrongPosition := CountCorrectColorWrongPosition([...]string{"V", "B", "B", "B"}, [...]string{"N", "V", "N", "N"})
	assert.That(onePegIsCorrectColorAndWrongPosition).IsEqualTo(1)

	ignoreAditionalPegsOfSameColor := CountCorrectColorWrongPosition([...]string{"V", "B", "B", "B"}, [...]string{"N", "V", "V", "N"})
	assert.That(ignoreAditionalPegsOfSameColor).IsEqualTo(1)

	ignorePegsWithCorrectColorAndPosition := CountCorrectColorWrongPosition([...]string{"V", "B", "B", "V"}, [...]string{"V", "V", "N", "N"})
	assert.That(ignorePegsWithCorrectColorAndPosition).IsEqualTo(1)

	recognizePegsAreCorrectColorsForMultipleColors := CountCorrectColorWrongPosition([...]string{"V", "R", "B", "B"}, [...]string{"R", "V", "N", "N"})
	assert.That(recognizePegsAreCorrectColorsForMultipleColors).IsEqualTo(2)
}
Example #11
0
func TestMaxAbsShouldFindMaxAbsWhenMaxIsNegative(t *testing.T) {
	assert := assert.New(t)
	slice := []float64{3, 7, 2, -8}
	max := MaxAbs(slice)
	assert.That(max).IsEqualTo(float64(8))
}
Example #12
0
func TestThatEmptyWorldStaysEmpty(t *testing.T) {
	assert := assert.New(t)
	assert.That(Tick(make(map[int]bool))).IsNotNil()
}
Example #13
0
func TestParamsShouldReturnEmptyStringWhenNotFound(t *testing.T) {
	assert := assert.New(t)
	param := FindParam("-in", []string{})
	assert.That(param).IsEqualTo("")
}
Example #14
0
func TestParamsShouldReturnNextElementFromArray(t *testing.T) {
	assert := assert.New(t)
	param := FindParam("-in", []string{"-in", "in"})
	assert.That(param).IsEqualTo("in")
}
Example #15
0
func TestPowerShouldReturnPowerOfSingleSample(t *testing.T) {
	assert := assert.New(t)
	assert.That(PowerOfSignal([]float64{1.0})).IsEqualTo(1.0)
}
Example #16
0
func TestGeneratorShouldGenerateRandomSliceInGivenSize(t *testing.T) {
	assert := assert.New(t)
	slice := Generator(rand.Float64)(5)
	assert.That(len(slice)).IsEqualTo(5)
}
Example #17
0
func TestMaxAbsShouldFindMaxFromMultipleElements(t *testing.T) {
	assert := assert.New(t)
	slice := []float64{3, 7, 2}
	max := MaxAbs(slice)
	assert.That(max).IsEqualTo(float64(7))
}
Example #18
0
func TestNormalizerShouldNormalizeSingleElement(t *testing.T) {
	assert := assert.New(t)
	slice := []float64{3}
	normalized := Normalize(slice)
	assert.That(normalized[0]).IsEqualTo(float64(1))
}
Example #19
0
func TestMaxAbsShouldFindMax(t *testing.T) {
	assert := assert.New(t)
	slice := []float64{6}
	max := MaxAbs(slice)
	assert.That(max).IsEqualTo(float64(6))
}
Example #20
0
func TestPowerShouldReturnAveragePowerOfTwoSamples(t *testing.T) {
	assert := assert.New(t)
	assert.That(PowerOfSignal([]float64{1.0, 2.0})).IsEqualTo(2.5)
}
Example #21
0
func TestGeneratorShouldUseRandomFunction(t *testing.T) {
	assert := assert.New(t)
	slice := Generator(arrayBasedRandomProvider([]float64{0.1, 1}))(2)
	assert.That(slice[0]).IsEqualTo(float64(0.1))
	assert.That(slice[1]).IsEqualTo(float64(1))
}