-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added missing DSAs #2
base: master
Are you sure you want to change the base?
Conversation
func TestBfs(t *testing.T) { | ||
list := dsa.AdjList2 | ||
|
||
result := Bfs(list, 6, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems you swapped accidentally the arguments
https://github.com/ThePrimeagen/kata-machine/blob/d9d8d06b8a1a2c9058168eb8ae059aec80d4e24c/src/__tests__/BFSGraphList.ts#L5
expected := []int{0, 1, 4, 5, 6} | ||
assert.Equal(t, expected, result, "Array should be: %v\nBut got: %v", expected, result) | ||
|
||
result = Bfs(list, 0, 6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems you swapped accidentally the arguments
https://github.com/ThePrimeagen/kata-machine/blob/master/src/__tests__/BFSGraphList.ts#L13
func TestBfs(t *testing.T) { | ||
matrix := dsa.AdjMatrix1 | ||
|
||
result := Bfs(matrix, 6, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems you swapped accidentally the arguments
https://github.com/ThePrimeagen/kata-machine/blob/d9d8d06b8a1a2c9058168eb8ae059aec80d4e24c/src/__tests__/BFSGraphMatrix.ts#L5
expected := []int{0, 1, 4, 5, 6} | ||
assert.Equal(t, expected, result, "Array should be: %v\nBut got: %v", expected, result) | ||
|
||
result = Bfs(matrix, 0, 6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems you swapped accidentally the arguments
https://github.com/ThePrimeagen/kata-machine/blob/d9d8d06b8a1a2c9058168eb8ae059aec80d4e24c/src/__tests__/BFSGraphMatrix.ts#L13
src/DSA/LRU/LRU_test.go
Outdated
lru := NewLRU[string, int](3) | ||
|
||
result := lru.Get("foo") | ||
assert.Nil(t, result, "Expected: nil, got: %v", result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lru.Get
doesn't return nillable value, but if we'll return *V then it'll be mess in tests with a lot of value dereferencing.
That's why I return additional boolean that means is it nil or not (like in Queue
kata-machine-go/src/DSA/Queue/Queue.go
Line 15 in 612588c
func (q *Queue[T]) Deque() (T, bool) { |
kata-machine-go/src/DSA/Queue/Queue_test.go
Lines 16 to 19 in 612588c
val, ok := list.Deque() | |
assert.True(t, ok, "Deque should return true, but returned false") | |
assert.Equal(t, 5, val, "Value should be 5, but is %d", val) | |
assert.Equal(t, 2, list.Length, "Length should be 2, but is %d", list.Length) |
)
src/DSA/Map/Map_test.go
Outdated
assert.Equal(t, 69, result, "Expected: 69, got: %v", result) | ||
|
||
result = mapp.Get("blaz") | ||
assert.Nil(t, result, "Expected: nil, got: %v", result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mapp.Delete
also returns a value, but it's never checked if deleting an unset key returns nil
, the current test cases only check if the map is the same length after deleting an unset key. Should I modify mapp.Delete
to also return a bool and add a test case for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm beginning to think that I had a wrong assumption all along and Delete
should not return any value. I'll make it return only a bool instead.
} | ||
|
||
result := Solve(maze, "x", dsa.Point{X: 10, Y: 0}, dsa.Point{X: 1, Y: 5}) | ||
assert.Equal(t, expected, result, "Expected: %v, got: %v", expected, result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ThePrimeagen has additional func "drawPath" (https://github.com/ThePrimeagen/kata-machine/blob/master/src/__tests__/MazeSolver.ts#L36), maybe we also need that
trie.Insert("foolish") | ||
trie.Insert("bar") | ||
|
||
result := trie.Find("fo") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ThePrimeagen also sort the result, maybe we also need that https://github.com/ThePrimeagen/kata-machine/blob/master/src/__tests__/Trie.ts#L10
assert.Equal(t, expected, result, "Expected: %v, got: %v", expected, result) | ||
|
||
trie.Delete("fool") | ||
expected = []string{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idx := rand.Intn(10001) | ||
|
||
data := []bool{} | ||
for i := 0; i < 10000; i++ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we can create the slice via make([]bool, 10000)
assert.Equal(t, idx, result, "Expected: %v, got: %v", idx, result) | ||
|
||
data = []bool{} | ||
for i := 0; i < 821; i++ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make([]bool, 821)
I added all the remaining DSAs that were present in ThePrimeagen/kata-machine. I also included them in
config.yaml
so that they will be generated withgo generate