Skip to content

Commit

Permalink
improve tests for road_network and search_unknown_length_array
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Tudose committed Jan 26, 2022
1 parent d9f95b1 commit 98f5b56
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions epi/road_network/solution.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package road_network

func FindBestProposals(h []HighwaySection, p []HighwaySection, n int) *HighwaySection {
func FindBestProposals(h []HighwaySection, p []HighwaySection, n int) HighwaySection {
// TODO - Add your code here
return nil
return HighwaySection{}
}
2 changes: 1 addition & 1 deletion epi/road_network/solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
utils "github.com/stefantds/go-epi-judge/test_utils"
)

type solutionFunc = func([]HighwaySection, []HighwaySection, int) *HighwaySection
type solutionFunc = func([]HighwaySection, []HighwaySection, int) HighwaySection

var solutions = []solutionFunc{
FindBestProposals,
Expand Down
8 changes: 8 additions & 0 deletions epi/search_unknown_length_array/array_unknown_length.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package search_unknown_length_array

type ArrayUnknownLength interface {
// Get returns the value at the given index in the array, if the index is valid.
// In this case the valid flag will be true.
// In case the index is out of bounds, it returns valid = false and an unspecified value.
Get(index int) (value int, valid bool)
}
2 changes: 1 addition & 1 deletion epi/search_unknown_length_array/solution.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package search_unknown_length_array

func BinarySearchUnknownLength(a []int, k int) int {
func BinarySearchUnknownLength(a ArrayUnknownLength, k int) int {
// TODO - Add your code here
return 0
}
13 changes: 11 additions & 2 deletions epi/search_unknown_length_array/solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
utils "github.com/stefantds/go-epi-judge/test_utils"
)

type solutionFunc = func([]int, int) int
type solutionFunc = func(ArrayUnknownLength, int) int

var solutions = []solutionFunc{
BinarySearchUnknownLength,
Expand Down Expand Up @@ -55,7 +55,7 @@ func TestBinarySearchUnknownLength(t *testing.T) {
if cfg.RunParallelTests {
t.Parallel()
}
result := s(tc.A, tc.K)
result := s(arrayUnknownLength(tc.A), tc.K)
if !reflect.DeepEqual(result, tc.ExpectedResult) {
t.Errorf("\ngot:\n%v\nwant:\n%v\ntest case:\n%+v\n", result, tc.ExpectedResult, tc)
}
Expand All @@ -66,3 +66,12 @@ func TestBinarySearchUnknownLength(t *testing.T) {
t.Fatalf("parsing error: %s", err)
}
}

type arrayUnknownLength []int

func (a arrayUnknownLength) Get(index int) (value int, valid bool) {
if index < 0 || index >= len(a) {
return -1, false
}
return a[index], true
}

0 comments on commit 98f5b56

Please sign in to comment.