Example #1
0
func TestGenerateHmacSha1Signature(t *testing.T) {
	sometext := []byte("sometext")
	somekey := []byte("somekey")
	assert.Equal(t, "jBXFV2mUBNP0/iVeVrb1x2TfSSc=", generateHmacSha1Signature(sometext, somekey), "sha1 baby!")
	assert.NotEqual(t, generateHmacSha1Signature(sometext, sometext),
		generateHmacSha1Signature(sometext, somekey), "processing arg1 twice")
	assert.NotEqual(t, generateHmacSha1Signature(somekey, somekey),
		generateHmacSha1Signature(sometext, somekey), "processing arg2 twice")
}
func TestMergeDiffs(t *testing.T) {
	diffs := NewImageDiffs()

	firstDiff := FindDiffForPointFuzzy(diffs, image.Pt(5, 5))
	secondDiff := FindDiffForPointFuzzy(diffs, image.Pt(75, 20))
	thirdDiff := FindDiffForPointFuzzy(diffs, image.Pt(75, 60))
	IncludePointInDiff(firstDiff, image.Pt(100, 75))

	assert.Equal(t, diffs.Len(), 3)
	assert.NotEqual(t, firstDiff, secondDiff)
	assert.NotEqual(t, secondDiff, thirdDiff)
	assert.NotEqual(t, firstDiff, thirdDiff)

	mergeDiffs(diffs)

	diff := FindDiffForPointFuzzy(diffs, image.Pt(75, 20))
	assert.Equal(t, diffs.Len(), 1)
	assert.Equal(t, *diff, image.Rect(5, 5, 100, 75))
}
func TestNewImpossibleComputer(t *testing.T) {
	var computer = NewImpossibleComputer()

	t.Log("is substitutable for Player")
	var player Player = computer
	assert.Equal(t, player, computer)

	t.Log("initializes with a Minimax instance")
	minimax, ok := computer.Minimax.(*Minimax)
	assert.True(t, ok)
	assert.NotEqual(t, minimax, (*Minimax)(nil))
}
Example #4
0
func TestGenerateCommonOauthParams(t *testing.T) {
	consumerKey := "consumerkey"
	nonce := "1234123412341234"
	timestamp := "1369804368"
	result := map[string]string{"oauth_consumer_key": "consumerkey",
		"oauth_nonce":            nonce,
		"oauth_signature_method": "HMAC-SHA1",
		"oauth_version":          "1.0",
		"oauth_timestamp":        timestamp,
	}

	assert.Equal(t, generateCommonOauthParams(consumerKey, nonce, timestamp), result, "common params")
	result["oauth_timestamp"] = "0"
	assert.NotEqual(t, generateCommonOauthParams(consumerKey, nonce, timestamp), result, "should fail")
	assert.Equal(t, generateCommonOauthParams(consumerKey, nonce, "0"), result, "data changed")

	result["oauth_timestamp"] = strconv.FormatInt(time.Now().Unix(), 10)
	assert.Equal(t, generateCommonOauthParams(consumerKey, nonce, ""), result, "using current time")

	result2 := generateCommonOauthParams(consumerKey, "", "")
	assert.True(t, len(result2["oauth_nonce"]) >= 18, "nonce is >= 18 chars (fails occaisionally because of a small random number)")
}