Religious Studies > SOPHIA Milestone > College of William & Mary - CS 1114 TurtleTest.java (All)
College of William & Mary - CS 1114TurtleTest.java import sofia.micro.*; import sofia.util.Random; // ------------------------------------------------------------------------- public class TurtleT... est extends TestCase { //~ Fields ................................................................ private Beach beach; private Turtle turtle; //~ Constructor ........................................................... // ---------------------------------------------------------- /** * Creates a new TurtleTest test object. */ public TurtleTest() { . } //~ Methods ............................................................... // ---------------------------------------------------------- /** * Sets up the test fixture. * Called before every test case method. */ public void setUp() { beach = new Beach(); turtle = new Turtle(); } // ---------------------------------------------------------- /*# Insert your own test methods here */ /** * tests that there is no turtle in the world. * first constructor */ public void testBeach() { assertEquals(0, beach.getObjects(Turtle.class).size()); } public void testBeach2() { beach = new Beach(5); assertEquals(5, beach.getObjects(Turtle.class).size()); } /** * tests that there are 0 turtles in the world */ public void testAddTurtle() { assertEquals(0, beach.getObjects(Turtle.class).size()); https://www.coursehero.com/file/57231150/TurtleTestjava/ This study resource was shared via CourseHero.com} /** * tets that the turtle turns right. */ public void testRandomTurn() { beach.add(turtle, 1, 1); Random.generator().setNextBooleans(true); turtle.randomTurn(); turtle.move(); //assertEquals(turtle.getDirection(), SOUTH); assertEquals(2, turtle.getGridY()); } public void testRandomTurn2() { beach.add(turtle, 1, 1); Random.generator().setNextBooleans(false); turtle.randomTurn(); turtle.move(); //assertEquals(turtle.getDirection(), SOUTH); assertEquals(0, turtle.getGridY()); } /** * tests that the turtle and the marker are at same location. */ public void testMove() { Marker marker = new Marker(); assertEquals(marker.getGridX(), turtle.getGridX()); assertEquals(marker.getGridY(), turtle.getGridY()); } /** * tests that the turtle moves 5 times * second move method. */ public void testMove2() { beach.add(turtle, 1, 1); turtle.move(5); assertEquals(6, turtle.getGridX()); } /** * tests that turtle moves randomly between 1 and 4 moves * in this case it moves once. */ public void testAct() { beach.add(turtle, 1, 1); Random.generator().setNextInts(0); This study resource was shared via CourseHero.comturtle.act(); assertEquals(2, turtle.getGridX()); [Show More]
Last updated: 2 years ago
Preview 1 out of 3 pages
Buy this document to get the full access instantly
Instant Download Access after purchase
Buy NowInstant download
We Accept:
Can't find what you want? Try our AI powered Search
Connected school, study & course
About the document
Uploaded On
Mar 20, 2021
Number of pages
3
Written in
This document has been written for:
Uploaded
Mar 20, 2021
Downloads
0
Views
99
In Scholarfriends, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Scholarfriends · High quality services·