コード例 #1
0
ファイル: countislands_test.go プロジェクト: RanaSumit/GoLang
func TestCountIslands(t *testing.T) {
	fmt.Println("Lab 1 - Part I \n---- Counting Islands ----")
	assert := assert.New(t)
	rows := [][]int{}

	row1 := []int{1, 1, 0, 0, 0}
	row2 := []int{1, 1, 0, 0, 0}
	row3 := []int{0, 0, 1, 0, 0}
	row4 := []int{0, 0, 0, 1, 1}

	rows = append(rows, row1)
	rows = append(rows, row2)
	rows = append(rows, row3)
	rows = append(rows, row4)

	fmt.Println(rows)
	assert.Equal(3, CountIslands(rows), "Number of islands should be 3")
}
コード例 #2
0
ファイル: cache_test.go プロジェクト: RanaSumit/GoLang
func TestCache(t *testing.T) {
	assert := assert.New(t)
	fmt.Println("Lab 1 - Part II \n---- LRU Cache ----")
	// Populates entries into the Cache
	l := New(CACHE_SIZE)
	l.Set(1, 10)
	l.Set(2, 20)
	l.Set(3, 30)

	assert.Equal(10, l.Get(1), "Get(1) should return 10")
	assert.Equal(20, l.Get(2), "Get(2) should return 20")
	assert.Equal(30, l.Get(3), "Get(3) should return 30")

	l.Set(4, 40)
	assert.Equal(40, l.Get(4), "Get(4) should return 40")
	// Checks Cache Invalidation
	assert.Equal(-1, l.Get(1), "Get(1) should return -1 as it was the least recently used entry")
}