Skip to content

Commit

Permalink
Implement new modification type 85 (left-behind material has departed)
Browse files Browse the repository at this point in the history
  • Loading branch information
geertw committed Aug 21, 2022
1 parent 9425e43 commit 642ab63
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 4 deletions.
7 changes: 4 additions & 3 deletions models/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ type Material struct {
DestinationPlanned Station `json:"destination_planned"`
Accessible bool `json:"accessible"`

Closed bool `json:"closed"`
RemainsBehind bool `json:"remains_behind"`
Added bool `json:"added"`
Closed bool `json:"closed"`
RemainsBehind bool `json:"remains_behind"`
Added bool `json:"added"`
AlreadyRemoved bool `json:"already_removed"`

Modifications []Modification
}
Expand Down
2 changes: 1 addition & 1 deletion models/departure.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (departure Departure) GetRemarksTips(language string) (remarks, tips []stri
if material.Closed {
closedMaterialUnits = append(closedMaterialUnits, *material.NormalizedNumber())
}
if material.RemainsBehind {
if material.RemainsBehind && !material.AlreadyRemoved {
leftBehindMaterialUnits = append(leftBehindMaterialUnits, *material.NormalizedNumber())
}
if material.Added {
Expand Down
62 changes: 62 additions & 0 deletions models/departure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,65 @@ func TestDepartureMaterialRemarksClosed(t *testing.T) {
t.Errorf("Remarks: expected %s, got %s", "Treinstellen 1234, 2345: niet instappen", remarks[0])
}
}

func TestDepartureMaterialRemarksRemainsBehindAlreadyRemoved(t *testing.T) {
var departure Departure = Departure{
Station: Station{
Code: "RTD",
NameMedium: "Rotterdam C.",
},
TrainWings: []TrainWing{
{
Material: []Material{
{
NaterialType: "ICM",
Number: "1234",
RemainsBehind: true,
AlreadyRemoved: true,
},
},
},
},
}

remarks, _ := departure.GetRemarksTips("nl")

if len(remarks) > 0 {
t.Errorf("Remarks: expected no remarks, got %d", len(remarks))
}

departure = Departure{
Station: Station{
Code: "RTD",
NameMedium: "Rotterdam C.",
},
TrainWings: []TrainWing{
{
Material: []Material{
{
NaterialType: "ICM",
Number: "1234",
RemainsBehind: true,
AlreadyRemoved: true,
},
{
NaterialType: "ICM",
Number: "4321",
RemainsBehind: false,
},
{
NaterialType: "ICM",
Number: "2345",
RemainsBehind: true,
},
},
},
},
}

remarks, _ = departure.GetRemarksTips("nl")

if remarks[0] != "Treinstel 2345 blijft achter in Rotterdam C." {
t.Errorf("Remarks: expected %s, got %s", "Treinstel 2345 blijft achter in Rotterdam C.", remarks[0])
}
}
3 changes: 3 additions & 0 deletions models/modification.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ const ModificationMaterialAdded = 83
// ModificationMaterialLeftBehind when material is left behind on a station
const ModificationMaterialLeftBehind = 84

// ModificationMaterialAlreadyRemoved when the material that was left behind has already been removed (driven away)
const ModificationMaterialAlreadyRemoved = 85

// Modification is a change (to the schedule) which is communicated to travellers
type Modification struct {
ModificationType int `json:"type"`
Expand Down
2 changes: 2 additions & 0 deletions parsers/dvsparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ func ParseDvsMessage(reader io.Reader) (departure models.Departure, err error) {
material.Added = true
case models.ModificationMaterialLeftBehind:
material.RemainsBehind = true
case models.ModificationMaterialAlreadyRemoved:
material.AlreadyRemoved = true
}
}

Expand Down

0 comments on commit 642ab63

Please sign in to comment.