@@ -45,7 +45,7 @@ describe("Rover class", function () {
4545 "Test message with status check command" ,
4646 commands
4747 ) ;
48- console . log ( "MESSAGE:" , message ) ;
48+ // console.log("MESSAGE:", message);
4949 let rover = new Rover ( 98382 ) ;
5050 let response = rover . receiveMessage ( message ) ;
5151 let roverStatus = response . results [ 0 ] . roverStatus ;
@@ -57,38 +57,90 @@ describe("Rover class", function () {
5757
5858 // 11 tests here!
5959 test ( "responds correctly to the mode change command" , function ( ) {
60+ let newPosition = 3579 ;
6061 let commands = [
6162 new Command ( "MODE_CHANGE" , "LOW_POWER" ) ,
62- new Command ( "STATUS_CHECK" ) ,
63- new Command ( "MOVE" ) ,
63+ new Command ( "STATUS_CHECK" , "" ) ,
64+ new Command ( "MOVE" , newPosition ) ,
6465 ] ;
6566
6667 let message = new Message (
6768 "Test message with mode change command" ,
6869 commands
6970 ) ;
71+ // console.log("///MESSAGE:///", message);
7072 let rover = new Rover ( 98382 ) ;
71-
7273 let response = rover . receiveMessage ( message ) ; // Check if the STATUS_CHECK command is found in the response
7374
7475 let statusCheckResult = response . results . find (
75- ( result ) => result . commandType === "STATUS_CHECK"
76+ ( result ) =>
77+ result &&
78+ result . command &&
79+ result . command . commandType === "STATUS_CHECK"
7680 ) ; // state the rover status if STATUS_CHECK command is found
7781
7882 if ( statusCheckResult ) {
7983 let roverStatus = statusCheckResult . roverStatus ;
8084 expect ( roverStatus . mode ) . toBe ( "NORMAL" ) ;
8185 expect ( roverStatus . generatorWatts ) . toBe ( 110 ) ;
8286 expect ( roverStatus . position ) . toBe ( 98382 ) ;
83- } else {
84- // handle if STATUS_CHECK command is not found
85- console . error ( "STATUS_CHECK command not found in the message" ) ;
8687 }
88+ // else {
89+ // // handle if STATUS_CHECK command is not found
90+ // console.error("STATUS_CHECK command not found in the message");
91+ // }
8792 } ) ;
8893
89- // // 12 tests here!
90- // test("responds with a false completed value when attempting to move in LOW_POWER mode", function () {});
94+ // 12 tests here!
95+ test ( "responds with a false completed value when attempting to move in LOW_POWER mode" , function ( ) {
96+ // let rover = new Rover(100);
97+ let rover = new Rover ( 4321 ) ; //initial position
98+ let commands = [
99+ new Command ( "MOVE" , 4321 ) , //move to same position
100+ new Command ( "STATUS_CHECK" ) ,
101+ new Command ( "MODE_CHANGE" , "LOW_POWER" ) ,
102+ new Command ( "MOVE" , 3579 ) , //move to different position
103+ new Command ( "STATUS_CHECK" ) ,
104+ ] ;
105+
106+ let message = new Message (
107+ "Test message with commands for LOW_POWER mode" ,
108+ commands
109+ ) ;
110+ let response = rover . receiveMessage ( message ) ;
91111
92- // // 13 tests here!
93- // test("responds with the position for the move command", function () {});
112+ expect ( response . message ) . toEqual (
113+ "Test message with commands for LOW_POWER mode"
114+ ) ;
115+ expect ( response . results [ 0 ] . completed ) . toBeTruthy ( ) ;
116+ expect ( response . results [ 1 ] . roverStatus . position ) . toEqual ( 4321 ) ;
117+ expect ( response . results [ 2 ] . completed ) . toBeTruthy ( ) ;
118+ expect ( response . results [ 3 ] . completed ) . toBeFalsy ( ) ;
119+ expect ( response . results [ 4 ] . roverStatus . position ) . toEqual ( 4321 ) ;
120+ expect ( response . results [ 4 ] . roverStatus . mode ) . toEqual ( "LOW_POWER" ) ;
121+ expect ( response . results [ 4 ] . roverStatus . generatorWatts ) . toEqual ( 110 ) ;
122+ } ) ;
123+ // 13 tests here!
124+ test ( "responds with the position for the move command" , function ( ) {
125+ // Create a new rover object with an initial position of 4321
126+ let rover = new Rover ( 4321 ) ;
127+
128+ // Define a new position for the move command
129+ let newPosition = 3579 ;
130+
131+ // Define commands for the message
132+ let commands = [
133+ new Command ( "MOVE" , newPosition ) , // Move to the new position
134+ new Command ( "STATUS_CHECK" ) , // Check rover status
135+ ] ;
136+
137+ // Create a new message with the defined commands
138+ let message = new Message ( "Test message with move command" , commands ) ;
139+
140+ // Receive the message and get the response
141+ let response = rover . receiveMessage ( message ) ;
142+
143+ // Test if the rover's position is updated to the new position specified in the MOVE command
144+ expect ( response . results [ 0 ] . roverStatus . position ) . toEqual ( newPosition ) ;
145+ } ) ;
94146} ) ;
0 commit comments