Ports have Ships ;TLDR
Challenge
Port now needs to have a ships property. When a Ship docks at a Port, the Port method needs to add that ship to its ships. When a Ship sets sail, the Port method needs to remove that ship from its ships.
To complete this challenge, you will need to:
- Discuss with your classmates how the domain model now looks.
- Create a new test spec for a
PortaddShipmethod. - Write the code that makes this test pass.
- Create a new test spec for a
PortremoveShipmethod. - Write the code that makes this test pass.
- Create a new test
Ship > gets added to port on instantiationin theShiptest suite. You'll need to checkship.currentPort.shipsto see if it contains yourShipinstance. - Write the code to make this pass. The
Shipconstructor will need to call the starting port's (this.currentPort)addShipmethod, passing itself in (remember the current instance is referred to withthis). - Add an extra assertion to the test for
Ship > can dock at a different portto test that theShip'scurrentPort'sshipscontains theShipinstance. You'll likely want to assert onship.currentPort.ships. - Write the code that makes this test pass.
- Modify the test for
Ship > can set sailto test that theShip's previouscurrentPort(you can useindexOfonship.itineraryto find this) no longer contains theShipinstance on itsshipsproperty (something likepreviousPort.ships). - Write the code that makes this test pass.
- Add, commit with a meaningful message, and push to GitHub.