Esempio n. 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))
}
Esempio n. 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))
}
Esempio n. 3
0
func TestListTemplatesSortedByName(t *testing.T) {
	assert := assert.New(t)
	output := new(bytes.Buffer)
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	httpmock.RegisterResponder("GET", "https://api.github.com/repos/github/gitignore/contents/",
		httpmock.NewStringResponder(200, `[
  {
    "name": "C.gitignore"
  },
  {
    "name": "A.gitignore"
  }
]
`))
	httpmock.RegisterResponder("GET", "https://api.github.com/repos/github/gitignore/contents/Global",
		httpmock.NewStringResponder(200, `[
  {
    "name": "B.gitignore"
  }
]
`))

	app([]string{"chtignore", "list"}, output)

	assert.ThatString(output.String()).IsEqualTo(fmt.Sprintln("A, B, C, JetBrains-build"))
}
Esempio n. 4
0
func TestDisplayVersion(t *testing.T) {
	assert := assert.New(t)
	output := new(bytes.Buffer)

	app([]string{"chtignore", "--version"}, output)

	assert.ThatString(output.String()).IsEqualTo(fmt.Sprintln("chtignore version unknown-snapshot"))
}
Esempio n. 5
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")
}
Esempio n. 6
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)
}
Esempio n. 7
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)
}
Esempio n. 8
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))
}
Esempio n. 9
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))
}
Esempio n. 10
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)
}
Esempio n. 11
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")
}
Esempio n. 12
0
func TestGetJetBrainsBuildTemplate(t *testing.T) {
	assert := assert.New(t)
	output := new(bytes.Buffer)
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	httpmock.RegisterResponder("GET", "https://raw.githubusercontent.com/github/gitignore/38d6cac990a82a1f7814571634e08295086763b5/Global/JetBrains.gitignore",
		httpmock.NewStringResponder(200, ".idea"))

	app([]string{"chtignore", "JetBrains-build"}, output)

	assert.ThatString(output.String()).IsEqualTo(
		`# JetBrains-build
.idea
`)
}
Esempio n. 13
0
func TestTemplateStartWithUpperCase(t *testing.T) {
	assert := assert.New(t)
	output := new(bytes.Buffer)
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	httpmock.RegisterResponder("GET", templateUrl("Java.gitignore"),
		httpmock.NewStringResponder(200, "*.class"))

	app([]string{"chtignore", "java"}, output)

	assert.ThatString(output.String()).IsEqualTo(
		`# Java
*.class
`)
}
Esempio n. 14
0
func TestGetMultipleTemplates(t *testing.T) {
	assert := assert.New(t)
	output := new(bytes.Buffer)
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	httpmock.RegisterResponder("GET", templateUrl("Java.gitignore"),
		httpmock.NewStringResponder(200, "*.class"))
	httpmock.RegisterResponder("GET", templateUrl("Go.gitignore"),
		httpmock.NewStringResponder(200, "*.o"))

	app([]string{"chtignore", "Java", "Go"}, output)

	assert.ThatString(output.String()).
		Contains(fmt.Sprintln("# Java\n*.class")).
		Contains(fmt.Sprintln("# Go\n*.o"))
}
Esempio n. 15
0
func TestGetUniqueGlobalTemplate(t *testing.T) {
	assert := assert.New(t)
	output := new(bytes.Buffer)
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	httpmock.RegisterResponder("GET", templateUrl("Vagrant.gitignore"),
		httpmock.NewStringResponder(404, "Not Found"))
	httpmock.RegisterResponder("GET", templateUrl("Global/Vagrant.gitignore"),
		httpmock.NewStringResponder(200, ".vagrant/"))

	app([]string{"chtignore", "Vagrant"}, output)

	assert.ThatString(output.String()).IsEqualTo(
		`# Vagrant
.vagrant/
`)
}
Esempio n. 16
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)
}
Esempio n. 17
0
func TestNormalizerShouldNormalizeSingleElement(t *testing.T) {
	assert := assert.New(t)
	slice := []float64{3}
	normalized := Normalize(slice)
	assert.That(normalized[0]).IsEqualTo(float64(1))
}
Esempio n. 18
0
func TestHelpShouldSearchWholeParamsList(t *testing.T) {
	assert := assert.New(t)
	result := ShouldDisplayHelp([]string{"", "", "", "-help"})
	assert.ThatBool(result).IsTrue()
}
Esempio n. 19
0
func TestHelpShouldReturnFalseIsNotAskedForHelp(t *testing.T) {
	assert := assert.New(t)
	result := ShouldDisplayHelp([]string{})
	assert.ThatBool(result).IsFalse()
}
Esempio n. 20
0
func TestMaxAbsShouldFindMaxFromMultipleElements(t *testing.T) {
	assert := assert.New(t)
	slice := []float64{3, 7, 2}
	max := MaxAbs(slice)
	assert.That(max).IsEqualTo(float64(7))
}
Esempio n. 21
0
func TestReaderShouldReadError(t *testing.T) {
	assert := assert.New(t)
	reader := strings.NewReader("ff")
	_, err := Read(reader)
	assert.ThatBool(err == nil).IsFalse()
}
Esempio n. 22
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))
}
Esempio n. 23
0
func TestPowerShouldReturnAveragePowerOfTwoSamples(t *testing.T) {
	assert := assert.New(t)
	assert.That(PowerOfSignal([]float64{1.0, 2.0})).IsEqualTo(2.5)
}
Esempio n. 24
0
func TestParamsShouldReturnNextElementFromArray(t *testing.T) {
	assert := assert.New(t)
	param := FindParam("-in", []string{"-in", "in"})
	assert.That(param).IsEqualTo("in")
}
Esempio n. 25
0
func TestListAvailableTemplates(t *testing.T) {
	assert := assert.New(t)
	output := new(bytes.Buffer)
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	httpmock.RegisterResponder("GET", "https://api.github.com/repos/github/gitignore/contents/",
		httpmock.NewStringResponder(200, `[
  {
    "name": "Go.gitignore",
    "path": "Go.gitignore",
    "sha": "daf913b1b347aae6de6f48d599bc89ef8c8693d6",
    "size": 266,
    "url": "https://api.github.com/repos/github/gitignore/contents/Go.gitignore?ref=master",
    "html_url": "https://github.com/github/gitignore/blob/master/Go.gitignore",
    "git_url": "https://api.github.com/repos/github/gitignore/git/blobs/daf913b1b347aae6de6f48d599bc89ef8c8693d6",
    "download_url": "https://raw.githubusercontent.com/github/gitignore/master/Go.gitignore",
    "type": "file",
    "_links": {
      "self": "https://api.github.com/repos/github/gitignore/contents/Go.gitignore?ref=master",
      "git": "https://api.github.com/repos/github/gitignore/git/blobs/daf913b1b347aae6de6f48d599bc89ef8c8693d6",
      "html": "https://github.com/github/gitignore/blob/master/Go.gitignore"
    }
  },
  {
    "name": "Java.gitignore",
    "path": "Java.gitignore",
    "sha": "32858aad3c383ed1ff0a0f9bdf231d54a00c9e88",
    "size": 189,
    "url": "https://api.github.com/repos/github/gitignore/contents/Java.gitignore?ref=master",
    "html_url": "https://github.com/github/gitignore/blob/master/Java.gitignore",
    "git_url": "https://api.github.com/repos/github/gitignore/git/blobs/32858aad3c383ed1ff0a0f9bdf231d54a00c9e88",
    "download_url": "https://raw.githubusercontent.com/github/gitignore/master/Java.gitignore",
    "type": "file",
    "_links": {
      "self": "https://api.github.com/repos/github/gitignore/contents/Java.gitignore?ref=master",
      "git": "https://api.github.com/repos/github/gitignore/git/blobs/32858aad3c383ed1ff0a0f9bdf231d54a00c9e88",
      "html": "https://github.com/github/gitignore/blob/master/Java.gitignore"
    }
  }
]
`))
	httpmock.RegisterResponder("GET", "https://api.github.com/repos/github/gitignore/contents/Global",
		httpmock.NewStringResponder(200, `[
  {
    "name": "Vagrant.gitignore",
    "path": "Global/Vagrant.gitignore",
    "sha": "a977916f6583710870b00d50dd7fddd6701ece11",
    "size": 10,
    "url": "https://api.github.com/repos/github/gitignore/contents/Global/Vagrant.gitignore?ref=master",
    "html_url": "https://github.com/github/gitignore/blob/master/Global/Vagrant.gitignore",
    "git_url": "https://api.github.com/repos/github/gitignore/git/blobs/a977916f6583710870b00d50dd7fddd6701ece11",
    "download_url": "https://raw.githubusercontent.com/github/gitignore/master/Global/Vagrant.gitignore",
    "type": "file",
    "_links": {
      "self": "https://api.github.com/repos/github/gitignore/contents/Global/Vagrant.gitignore?ref=master",
      "git": "https://api.github.com/repos/github/gitignore/git/blobs/a977916f6583710870b00d50dd7fddd6701ece11",
      "html": "https://github.com/github/gitignore/blob/master/Global/Vagrant.gitignore"
    }
  }
]
`))

	app([]string{"chtignore", "list"}, output)

	assert.ThatString(output.String()).IsEqualTo(fmt.Sprintln("Go, Java, JetBrains-build, Vagrant"))
}
Esempio n. 26
0
func TestHelpShouldReturnTrue6(t *testing.T) {
	assert := assert.New(t)
	result := ShouldDisplayHelp([]string{"/?"})
	assert.ThatBool(result).IsTrue()
}
Esempio n. 27
0
func TestMaxAbsShouldFindMax(t *testing.T) {
	assert := assert.New(t)
	slice := []float64{6}
	max := MaxAbs(slice)
	assert.That(max).IsEqualTo(float64(6))
}
Esempio n. 28
0
func TestParamsShouldReturnEmptyStringWhenNotFound(t *testing.T) {
	assert := assert.New(t)
	param := FindParam("-in", []string{})
	assert.That(param).IsEqualTo("")
}
Esempio n. 29
0
func TestThatEmptyWorldStaysEmpty(t *testing.T) {
	assert := assert.New(t)
	assert.That(Tick(make(map[int]bool))).IsNotNil()
}
Esempio n. 30
0
func TestPowerShouldReturnPowerOfSingleSample(t *testing.T) {
	assert := assert.New(t)
	assert.That(PowerOfSignal([]float64{1.0})).IsEqualTo(1.0)
}