-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathcheapest_flights_test.go
36 lines (31 loc) · 1.26 KB
/
cheapest_flights_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package graph
import (
"math"
"testing"
)
/*
TestCheapestFlights tests solution(s) with the following signature and problem description:
func CheapestFlights(flights [][]int, cityCount, source, destination, maxStops int) int
Given a list of flights each with a source and destination and a price, a maximum number of stops,
source, and destination cities, return the cheapest costs not exceeding the maximum number of stops
to reach from source city to destination.
*/
func TestCheapestFlights(t *testing.T) {
tests := []struct {
flight [][]int
cityCount, source, destination, maxStops, cheapestCost int
}{
{[][]int{{0, 1, math.MaxInt64}}, 3, 0, 2, 2, -1},
{[][]int{{0, 1, 10}, {1, 2, 10}, {0, 2, 5}}, 3, 0, 2, 2, 5},
{[][]int{{0, 1, 10}, {1, 2, 10}, {0, 2, 5}}, 3, 0, 2, 2, 5},
{[][]int{{0, 1, 10}, {1, 2, 10}, {0, 2, 10}}, 3, 0, 2, 2, 10},
{[][]int{{0, 1, 10}, {1, 2, 10}, {0, 2, 20}}, 3, 0, 2, 1, 20},
{[][]int{{0, 1, 10}, {1, 2, 10}, {0, 2, 20}}, 3, 0, 2, 1, 20},
}
for i, test := range tests {
got := CheapestFlights(test.flight, test.cityCount, test.source, test.destination, test.maxStops)
if got != test.cheapestCost {
t.Fatalf("Failed test case #%d. Want %d got %d", i, test.cheapestCost, got)
}
}
}