func TestSpatialEntropyCalculation(t *testing.T) {
	matchPlain := match.Match{
		Pattern: "spatial",
		I:       0,
		J:       5,
		Token:   "asdfgh",
		DictionaryName:"qwerty",
	}
	entropy := SpatialEntropy(matchPlain, 0, 0)
	assert.Equal(t, 9.754887502163468, entropy)

	matchShift := match.Match{
		Pattern: "spatial",
		I:       0,
		J:       5,
		Token:   "asdFgh",
		DictionaryName:"qwerty",
	}
	entropyShift := SpatialEntropy(matchShift, 0, 1)
	assert.Equal(t, 12.562242424221072, entropyShift)

	matchTurn := match.Match{
		Pattern: "spatial",
		I:       0,
		J:       5,
		Token:   "asdcxz",
		DictionaryName:"qwerty",
	}
	entropyTurn := SpatialEntropy(matchTurn, 2, 0)
	assert.Equal(t, 14.080500893768884, entropyTurn)
}
func TestSequenceMatch(t *testing.T) {
	//abcdjibjacLMNOPjibjac1234  => abcd LMNOP 1234

	matches := SequenceMatch("abcdjibjacLMNOPjibjac1234")
	assert.Len(t, matches, 3, "Lenght should be 2")

	for _, match := range matches {
		if match.DictionaryName == "lower" {
			assert.Equal(t, 0, match.I)
			assert.Equal(t, 3, match.J)
			assert.Equal(t, "abcd", match.Token)
			assert.NotZero(t, match.Entropy, "Entropy should be set")
		} else if match.DictionaryName == "upper" {
			assert.Equal(t, 10, match.I)
			assert.Equal(t, 14, match.J)
			assert.Equal(t, "LMNOP", match.Token)
			assert.NotZero(t, match.Entropy, "Entropy should be set")
		} else if match.DictionaryName == "digits" {
			assert.Equal(t, 21, match.I)
			assert.Equal(t, 24, match.J)
			assert.Equal(t, "1234", match.Token)
			assert.NotZero(t, match.Entropy, "Entropy should be set")
		} else {
			assert.True(t, false, "Unknow dictionary")
		}
	}
}
//l33t
func TestLeetSubTable(t *testing.T) {
	subs := relevantL33tSubtable("password")
	assert.Len(t, subs, 0, "password should produce no leet subs")

	subs = relevantL33tSubtable("p4ssw0rd")
	assert.Len(t, subs, 2, "p4ssw0rd should produce 2 subs")

	subs = relevantL33tSubtable("1eet")
	assert.Len(t, subs, 2, "1eet should produce 2 subs")
	assert.Equal(t, subs["i"][0], "1")
	assert.Equal(t, subs["l"][0], "1")

	subs = relevantL33tSubtable("4pple@pple")
	assert.Len(t, subs, 1, "4pple@pple should produce 1 subs")
	assert.Len(t, subs["a"], 2)

}
func TestRepeatMatchEntropyCalculation(t *testing.T) {
	matchRepeat := match.Match{
		Pattern: "repeat",
		I:       0,
		J:       4,
		Token:   "aaaaa",
	}
	entropy := RepeatEntropy(matchRepeat)
	assert.Equal(t, 7.022367813028454, entropy)
}
func TestDictionaryEntropyCalculation(t *testing.T) {
	match := match.Match{
		Pattern: "dictionary",
		I:       0,
		J:       4,
		Token:   "first",
	}

	entropy := DictionaryEntropy(match, float64(20))

	assert.Equal(t, 4.321928094887363, entropy)
}
func TestDateSepMatch(t *testing.T) {
	matches := DateSepMatch("1991-09-11jibjab11.9.1991")

	assert.Len(t, matches, 2, "Length should be 2")

	for _, match := range matches {
		if match.Separator == "." {
			assert.Equal(t, 16, match.I)
			assert.Equal(t, 25, match.J)
			assert.Equal(t, int64(9), match.Day)
			assert.Equal(t, int64(11), match.Month)
			assert.Equal(t, int64(1991), match.Year)
		} else {
			assert.Equal(t, 0, match.I)
			assert.Equal(t, 10, match.J)
			assert.Equal(t, int64(9), match.Day)
			assert.Equal(t, int64(11), match.Month)
			assert.Equal(t, int64(1991), match.Year)
		}
	}

}
func TestSequenceCalculation(t *testing.T) {
	matchLower := match.Match{
		Pattern: "sequence",
		I:       0,
		J:       4,
		Token:   "jklmn",
	}
	entropy := SequenceEntropy(matchLower, len("abcdefghijklmnopqrstuvwxyz"), true)
	assert.Equal(t, 7.022367813028454, entropy)

	matchUpper := match.Match{
		Pattern: "sequence",
		I:       0,
		J:       4,
		Token:   "JKLMN",
	}
	entropy = SequenceEntropy(matchUpper, len("abcdefghijklmnopqrstuvwxyz"), true)
	assert.Equal(t, 8.022367813028454, entropy)

	matchUpperDec := match.Match{
		Pattern: "sequence",
		I:       0,
		J:       4,
		Token:   "JKLMN",
	}
	entropy = SequenceEntropy(matchUpperDec, len("abcdefghijklmnopqrstuvwxyz"), false)
	assert.Equal(t, 9.022367813028454, entropy)

	matchDigit := match.Match{
		Pattern: "sequence",
		I:       0,
		J:       4,
		Token:   "34567",
	}
	entropy = SequenceEntropy(matchDigit, 10, true)
	assert.Equal(t, 5.643856189774724, entropy)
}
func TestRepeatMatch(t *testing.T) {
	//aaaBbBb
	matches := RepeatMatch("aaabBbB")

	assert.Len(t, matches, 2, "Lenght should be 2")

	for _, match := range matches {
		if strings.ToLower(match.DictionaryName) == "b" {
			assert.Equal(t, 3, match.I)
			assert.Equal(t, 6, match.J)
			assert.Equal(t, "bBbB", match.Token)
			assert.NotZero(t, match.Entropy, "Entropy should be set")
		} else {
			assert.Equal(t, 0, match.I)
			assert.Equal(t, 2, match.J)
			assert.Equal(t, "aaa", match.Token)
			assert.NotZero(t, match.Entropy, "Entropy should be set")

		}
	}
}
Example #9
0
func TestNchoseK100and2(t *testing.T) {
	nCk := NChoseK(100, 2)

	assert.Equal(t, float64(4950), nCk, "100 chose 2 should equal 4950")
}
Example #10
0
func TestNChoseKWereKis0(t *testing.T) {
	nCk := NChoseK(50, 0)

	assert.Equal(t, float64(1), nCk, "When K is 0 then 1")
}
Example #11
0
func TestNChoseKwereNlessK(t *testing.T) {
	nCk := NChoseK(1, 2)

	assert.Equal(t, float64(0), nCk, "When n is less than k always 0")
}
Example #12
0
func TestCalculateDegreeMacKepad(t *testing.T) {
	avgDegreeQwert := BuildMacKeypad().CalculateAvgDegree()

	assert.Equal(t, float64(0.65625), avgDegreeQwert, "Avg degree for mackeyPad should be 0.65625")
}
Example #13
0
func TestCalculateDegreeKeypad(t *testing.T) {
	avgDegreeQwert := BuildKeypad().CalculateAvgDegree()

	assert.Equal(t, float64(0.6333333333333333), avgDegreeQwert, "Avg degree for keypad should be 0.6333333333333333")
}
Example #14
0
func TestCalculateDegreeDvorak(t *testing.T) {
	avgDegreeQwert := BuildDvorak().CalculateAvgDegree()

	assert.Equal(t, float64(1.5319148936170213), avgDegreeQwert, "Avg degree for dvorak should be 1.53191489361702135")
}
Example #15
0
/*
nbutton: Really the value is not as important to me than they don't change, which happened during development.
*/
func TestCalculateDegreeQwert(t *testing.T) {
	avgDegreeQwert := BuildQwerty().CalculateAvgDegree()

	assert.Equal(t, float64(1.5319148936170213), avgDegreeQwert, "Avg degree for qwerty should be 1.5319148936170213")
}