05d39697a11a631e056811a3911af5a73602fe9d.svn-base 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package model
  2. import (
  3. "reflect"
  4. "testing"
  5. )
  6. func TestItinerary_CreateEmpty(t *testing.T) {
  7. i := Itinerary{}
  8. var legs []Leg
  9. if !reflect.DeepEqual(i.Legs, legs) {
  10. t.Errorf("should be equal")
  11. }
  12. if i.InitialDepartureLocation() != "" {
  13. t.Errorf("InitialDepartureLocation() = %s; want = %s",
  14. i.InitialDepartureLocation(), "")
  15. }
  16. if i.FinalArrivalLocation() != "" {
  17. t.Errorf("FinalArrivalLocation() = %s; want = %s",
  18. i.FinalArrivalLocation(), "")
  19. }
  20. }
  21. func TestItinerary_IsExpected_EmptyItinerary(t *testing.T) {
  22. i := Itinerary{}
  23. e := HandlingEvent{}
  24. if got, want := i.IsExpected(e), true; got != want {
  25. t.Errorf("IsExpected() = %v; want = %v", got, want)
  26. }
  27. }
  28. type eventExpectedTest struct {
  29. act HandlingActivity
  30. exp bool
  31. }
  32. var eventExpectedTests = []eventExpectedTest{
  33. {HandlingActivity{}, true},
  34. {HandlingActivity{Type: Receive, Location: SESTO}, true},
  35. {HandlingActivity{Type: Receive, Location: AUMEL}, false},
  36. {HandlingActivity{Type: Load, Location: AUMEL, VoyageNumber: "001A"}, true},
  37. {HandlingActivity{Type: Load, Location: CNHKG, VoyageNumber: "001A"}, false},
  38. {HandlingActivity{Type: Unload, Location: CNHKG, VoyageNumber: "001A"}, true},
  39. {HandlingActivity{Type: Unload, Location: SESTO, VoyageNumber: "001A"}, false},
  40. {HandlingActivity{Type: Claim, Location: CNHKG}, true},
  41. {HandlingActivity{Type: Claim, Location: SESTO}, false},
  42. }
  43. func TestItinerary_IsExpected(t *testing.T) {
  44. i := Itinerary{Legs: []Leg{
  45. {
  46. VoyageNumber: "001A",
  47. LoadLocation: SESTO,
  48. UnloadLocation: AUMEL,
  49. },
  50. {
  51. VoyageNumber: "001A",
  52. LoadLocation: AUMEL,
  53. UnloadLocation: CNHKG,
  54. },
  55. }}
  56. for _, tt := range eventExpectedTests {
  57. e := HandlingEvent{
  58. Activity: tt.act,
  59. }
  60. if got := i.IsExpected(e); got != tt.exp {
  61. t.Errorf("IsExpected() = %v; want = %v", got, tt.exp)
  62. }
  63. }
  64. }