Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i need help where it says to do the method. this is Java, running in eclipse. utive java - Eclipse IDE Consecutive.java X Implement a

image text in transcribedi need help where it says to do the method. this is Java, running in eclipse.
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
utive java - Eclipse IDE Consecutive.java X Implement a method (@code has Consecutive()}) to test whether the user entered a user-specified number of consecutive, same-valued numbers @author your name 2 version 1.0.0 2020-01-26 initial version per assignment 3 */ 34 public class NConsecutive 370 /** Test whether (@code values) has a specified number of consecutive, * same-valued elements * @param values The array of numbers to check for a sequence of consecutive, same valued elements * @param runLength The number of occurrences we are looking for in (@code values) return code true) if at least one sequence of code runLength), same valued entries exists; (@code False} otherwise public static boolean hasConsecutive(int[] values, int runLength ) SSTUB return false; ) // end has Consecutive() * You can use the main() method to test your implementation of * hasConsecutive() * @param ares -unused public static void main(Strinel] args) I STUB Writable Smart Insert 59 U NConsecutive.java CUIJAVA 10/* @formatter:off) 24 25 package edu.wit.dcsn.comp1050. lab01; 270 import static org.junit.jupiter.api. Assertions.assertAll ;O 430 /** 44 * JUnit tests for the NConsecutive class. All public and package visible * methods are tested. 46 *

* @author * @version 1.0.0 2018-02-10 initial set of tests * Oversion 1.1.0 2018-05-18 'fix' messages to indicate end of tests but not always 'all successful * @version 1.2.0 2019-01-21 clean up; add timeouts; revise structure to use Testinfo instead of certain hard-coded text @version 2.0.0 2019-01-26

  • restructure tests to enable all tests to run even if one fails;
  • restructure tests to use utility methods;
  • correct expected result for test of empty array with runLength @
* @version 2.1.0 2019-05-01 add tests for failures in student submissions * @version 2.2.0 2019-05-02
  • disable System.exit() during testing
  • further restructuring to run each test individually timed
* @version 2.3.0 2019-12-14 enhance testing based on creative (wrong) solution @version 2.4.0 2020-01-26
  • switch to new testing infrastructure
  • some restructuring to reduce redundant code
  • add test for negative {@code runLength}
74 @DisplayName( "Consecutive" ) 75 @TestInstance( Lifecycle.PER_CLASS) 76 @TestMethodOrder( OrderAnnotation.class) 77 class NConsecutive MRTests extends DMRJUnitTestsbase 000 Writables - UNLOecutive.java
  • some restructuring to reduce redundant code
  • add test for negative {@code runLength) @DisplayName("Consecutive" ) @TestInstance( Lifecycle.PER_CLASS) 76 TestMethodOrder( OrderAnnotation.class) 77 class NConsecutive DMRTests extends DMRJUnitTests Base ** * Utility method to execute hasConsecutive() with provided arguments. * @param values corresponding actual argument for the test * @param runLength corresponding actual argument for the test * @param expectedResult expected return value from has Consecutive() * @param isLast Test InGroup flag to infrastructure if last test is running */ void doTestHasConsecutive( final int[] values, final int runLength, final boolean expectedResult, final boolean islastTestInGroup) I startHas Consecutive Test( this.current TestsAttempted, values, runLength, expectedResult ); this.lastTest InGroupIsRunning - islastTest InGroup assertTimeoutPreemptively( testTimelimit, boolean actualResult = NConsecutive.hasConsecutive( values, runLength); writeLog("\tactual: %%n", actual Result): H ULLULILULUVU N CUliseculve.java NConsecutive.hasConsecutive( values, runLength); writeLog("\tactual: %%n", actualResult); assertEquals( expectedResult, actualResult ) ; this.currentTestPassed = true; I/ omitting causes incorrect fail message in detailed log testPassed(); // temp fix } // end doTestHasConsecutive() * Utility method to start a test to be performed @param testSequence sequence number of this test case * @param values corresponding actual argument for the test * @param runLength corresponding actual argument for the test * @param expectedResult expected return value from hasConsecutive private void startHas ConsecutiveTest( final int testSequence, final int[] values, final int runLength, final boolean expectedResult ) 136 137 1380 139 140 // count this test this.currentTestsAttempted++; determineStubBehavior( I expectedResult ); // stub returns false // display message describing this test writeLog("%[%,d, %,d%s) Testing: has Consecutive( %s, %,d >&n" "\texpect: %b%n", this.current TestGroup, Writable C N Consecutive.java writeLog( "Xn[%,d, %,dxs) Testing: has Consecutive(%5, %,d)Xn" + "\texpect: %%n", this.current TestGroup, this.current TestsAttempted, this.stubBehaviorTag, Arrays.toString( values ), runLength, expectedResult); } 11 end startHasConsecutive Test(); 162 163 1640 165 166 * Test method for * {@link edu.wit.dcsn.comp1850. lab01. NConsecutivehasConsecutive(int[], int)). 167 1680 169 170 @Test @DisplayName( "hasNConsecutive()" ) @Order( 10100 ) void testHas Consecutive() final boolean IS_NOT_LAST_TEST_IN_GROUP = final boolean IS_LAST_TEST_IN_GROUP = false; true; assertALL () -> final int[] testValues = { 1, 1}; final int runLength = 1; final boolean expectedResult = true; doTestHasConsective( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); () -> final int[] testValues = { 1 }; final int runLength = 1; final boolean expectedResult = true Writ ILLUUVCUIJAV U NConsecutive.java () -> final int[] testValues = {1}; final int runLength = 1; final boolean expectedResult = true; doTestHasConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); () -> final int[] testValues = { 1, 2, 3}; final int runLength = 2; final boolean expectedResult = false; doTestHasConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); () -> final int[] testValues = { 1, 1, 1, 1}; final int runLength = 2; final boolean expectedResult = true; 219 220 doTestHasConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); final int[] testValues = { 1, 1, 1, 1); final int runLength - 3; final boolean expectedResult = true; doTestHasConsecutive( testValues, runlaneth Wri CUISCOUVE.dvd tinal boolean expectedKesult = true; doTestHas NConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); () -> final int[] testValues = { 1, 1, 1, 1); final int runLength = 4; final boolean expectedResult = true; 243 244 doTestHasConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); }, () -> fihal int[] testValues = { 1, 1, 1, 1}; final int runLength = 5; final boolean expectedResult = false; doTestHasConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP ) ; }, () -> final int[] testValues = { 1, 1, 2, 3 }; final int runLength = 2; final boolean expectedResult = true; doTestHasConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); Wri W wJU N CUSELUUVE Uljava NConsecutive.java doTestHasConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP ) ; ()-> final int[] testValues = { 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3 }; final int runLength = 14 ; final boolean expected Result = true; doTestHas Consecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); () -> final int[] testValues = { 1, 2, 3, 4, 4); final int runLength = 2; final boolean expectedResult = true; doTestHas Consecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); 299 300 301 final int[] testValues = { 1, 2, 3, 4, 5 }; final int runLength - 7; final boolean expectedResult false; 302 303 304 305 306 307 308 doTestHas Consecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); final int[] testValues = { 10, 10, 10, 10, 10, 10 }; final int runLength = 17; final boolean expectedResult = false; doTestHasConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); final int[] testValues = { 1, 2, 1, 2}; final int runLength = 2; final boolean expectedResult = false; doTestHas Consecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); I A GROUP); }, () -> final int[] testValues = { 1, 2, 1, 2}; final int runLength = 0; final boolean expectedResult = false; doTestHas Consecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP ) ; Writable CONSELUuve.ava IS_NOT_LAST_TEST_IN_GROUP); final int[] testValues = {}; final int runLength = 0; final boolean expectedResult = false; doTestHasConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); final int[] testValues = {}; final int runLength = 1; final boolean expectedResult = false; doTestHasNConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); final int[] testValues = { 1, 2, 2, 1, 1, 2, 2, 1); final int runLength - 3; final boolean expectedResult = false; doTestHas NConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); final int[] testValues . { 1, 2, 2, 1, 1, 2, 2, 1); final int runLength - -3; final hoolean evnertedResults false () -> final int[] testValues = {}; final int runLength = 1; final boolean expected Result = false; doTestHasConsecutive testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); final int[] testValues = { 1, 2, 2, 1, 1, 2, 2, 1); final int runLength = 3; final boolean expectedResult = false; doTestHasConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); () -> final int[] testValues = { 1, 2, 2, 1, 1, 2, 2, 1 } } final int runLength = -3; final boolean expectedResult = false; 387 doTestHas NConsecutive( testValues, runLength, expectedResult, IS_LAST_TEST_IN_GROUP); ); // end assertall } // end testHas Consecutive() // end class NConsecutive MRTests } utive java - Eclipse IDE Consecutive.java X Implement a method (@code has Consecutive()}) to test whether the user entered a user-specified number of consecutive, same-valued numbers @author your name 2 version 1.0.0 2020-01-26 initial version per assignment 3 */ 34 public class NConsecutive 370 /** Test whether (@code values) has a specified number of consecutive, * same-valued elements * @param values The array of numbers to check for a sequence of consecutive, same valued elements * @param runLength The number of occurrences we are looking for in (@code values) return code true) if at least one sequence of code runLength), same valued entries exists; (@code False} otherwise public static boolean hasConsecutive(int[] values, int runLength ) SSTUB return false; ) // end has Consecutive() * You can use the main() method to test your implementation of * hasConsecutive() * @param ares -unused public static void main(Strinel] args) I STUB Writable Smart Insert 59 U NConsecutive.java CUIJAVA 10/* @formatter:off) 24 25 package edu.wit.dcsn.comp1050. lab01; 270 import static org.junit.jupiter.api. Assertions.assertAll ;O 430 /** 44 * JUnit tests for the NConsecutive class. All public and package visible * methods are tested. 46 *

    * @author * @version 1.0.0 2018-02-10 initial set of tests * Oversion 1.1.0 2018-05-18 'fix' messages to indicate end of tests but not always 'all successful * @version 1.2.0 2019-01-21 clean up; add timeouts; revise structure to use Testinfo instead of certain hard-coded text @version 2.0.0 2019-01-26

    • restructure tests to enable all tests to run even if one fails;
    • restructure tests to use utility methods;
    • correct expected result for test of empty array with runLength @
    * @version 2.1.0 2019-05-01 add tests for failures in student submissions * @version 2.2.0 2019-05-02
    • disable System.exit() during testing
    • further restructuring to run each test individually timed
    * @version 2.3.0 2019-12-14 enhance testing based on creative (wrong) solution @version 2.4.0 2020-01-26
    • switch to new testing infrastructure
    • some restructuring to reduce redundant code
    • add test for negative {@code runLength}
    74 @DisplayName( "Consecutive" ) 75 @TestInstance( Lifecycle.PER_CLASS) 76 @TestMethodOrder( OrderAnnotation.class) 77 class NConsecutive MRTests extends DMRJUnitTestsbase 000 Writables - UNLOecutive.java
  • some restructuring to reduce redundant code
  • add test for negative {@code runLength) @DisplayName("Consecutive" ) @TestInstance( Lifecycle.PER_CLASS) 76 TestMethodOrder( OrderAnnotation.class) 77 class NConsecutive DMRTests extends DMRJUnitTests Base ** * Utility method to execute hasConsecutive() with provided arguments. * @param values corresponding actual argument for the test * @param runLength corresponding actual argument for the test * @param expectedResult expected return value from has Consecutive() * @param isLast Test InGroup flag to infrastructure if last test is running */ void doTestHasConsecutive( final int[] values, final int runLength, final boolean expectedResult, final boolean islastTestInGroup) I startHas Consecutive Test( this.current TestsAttempted, values, runLength, expectedResult ); this.lastTest InGroupIsRunning - islastTest InGroup assertTimeoutPreemptively( testTimelimit, boolean actualResult = NConsecutive.hasConsecutive( values, runLength); writeLog("\tactual: %%n", actual Result): H ULLULILULUVU N CUliseculve.java NConsecutive.hasConsecutive( values, runLength); writeLog("\tactual: %%n", actualResult); assertEquals( expectedResult, actualResult ) ; this.currentTestPassed = true; I/ omitting causes incorrect fail message in detailed log testPassed(); // temp fix } // end doTestHasConsecutive() * Utility method to start a test to be performed @param testSequence sequence number of this test case * @param values corresponding actual argument for the test * @param runLength corresponding actual argument for the test * @param expectedResult expected return value from hasConsecutive private void startHas ConsecutiveTest( final int testSequence, final int[] values, final int runLength, final boolean expectedResult ) 136 137 1380 139 140 // count this test this.currentTestsAttempted++; determineStubBehavior( I expectedResult ); // stub returns false // display message describing this test writeLog("%[%,d, %,d%s) Testing: has Consecutive( %s, %,d >&n" "\texpect: %b%n", this.current TestGroup, Writable C N Consecutive.java writeLog( "Xn[%,d, %,dxs) Testing: has Consecutive(%5, %,d)Xn" + "\texpect: %%n", this.current TestGroup, this.current TestsAttempted, this.stubBehaviorTag, Arrays.toString( values ), runLength, expectedResult); } 11 end startHasConsecutive Test(); 162 163 1640 165 166 * Test method for * {@link edu.wit.dcsn.comp1850. lab01. NConsecutivehasConsecutive(int[], int)). 167 1680 169 170 @Test @DisplayName( "hasNConsecutive()" ) @Order( 10100 ) void testHas Consecutive() final boolean IS_NOT_LAST_TEST_IN_GROUP = final boolean IS_LAST_TEST_IN_GROUP = false; true; assertALL () -> final int[] testValues = { 1, 1}; final int runLength = 1; final boolean expectedResult = true; doTestHasConsective( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); () -> final int[] testValues = { 1 }; final int runLength = 1; final boolean expectedResult = true Writ ILLUUVCUIJAV U NConsecutive.java () -> final int[] testValues = {1}; final int runLength = 1; final boolean expectedResult = true; doTestHasConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); () -> final int[] testValues = { 1, 2, 3}; final int runLength = 2; final boolean expectedResult = false; doTestHasConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); () -> final int[] testValues = { 1, 1, 1, 1}; final int runLength = 2; final boolean expectedResult = true; 219 220 doTestHasConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); final int[] testValues = { 1, 1, 1, 1); final int runLength - 3; final boolean expectedResult = true; doTestHasConsecutive( testValues, runlaneth Wri CUISCOUVE.dvd tinal boolean expectedKesult = true; doTestHas NConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); () -> final int[] testValues = { 1, 1, 1, 1); final int runLength = 4; final boolean expectedResult = true; 243 244 doTestHasConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); }, () -> fihal int[] testValues = { 1, 1, 1, 1}; final int runLength = 5; final boolean expectedResult = false; doTestHasConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP ) ; }, () -> final int[] testValues = { 1, 1, 2, 3 }; final int runLength = 2; final boolean expectedResult = true; doTestHasConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); Wri W wJU N CUSELUUVE Uljava NConsecutive.java doTestHasConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP ) ; ()-> final int[] testValues = { 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3 }; final int runLength = 14 ; final boolean expected Result = true; doTestHas Consecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); () -> final int[] testValues = { 1, 2, 3, 4, 4); final int runLength = 2; final boolean expectedResult = true; doTestHas Consecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); 299 300 301 final int[] testValues = { 1, 2, 3, 4, 5 }; final int runLength - 7; final boolean expectedResult false; 302 303 304 305 306 307 308 doTestHas Consecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); final int[] testValues = { 10, 10, 10, 10, 10, 10 }; final int runLength = 17; final boolean expectedResult = false; doTestHasConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); final int[] testValues = { 1, 2, 1, 2}; final int runLength = 2; final boolean expectedResult = false; doTestHas Consecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); I A GROUP); }, () -> final int[] testValues = { 1, 2, 1, 2}; final int runLength = 0; final boolean expectedResult = false; doTestHas Consecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP ) ; Writable CONSELUuve.ava IS_NOT_LAST_TEST_IN_GROUP); final int[] testValues = {}; final int runLength = 0; final boolean expectedResult = false; doTestHasConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); final int[] testValues = {}; final int runLength = 1; final boolean expectedResult = false; doTestHasNConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); final int[] testValues = { 1, 2, 2, 1, 1, 2, 2, 1); final int runLength - 3; final boolean expectedResult = false; doTestHas NConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); final int[] testValues . { 1, 2, 2, 1, 1, 2, 2, 1); final int runLength - -3; final hoolean evnertedResults false () -> final int[] testValues = {}; final int runLength = 1; final boolean expected Result = false; doTestHasConsecutive testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); final int[] testValues = { 1, 2, 2, 1, 1, 2, 2, 1); final int runLength = 3; final boolean expectedResult = false; doTestHasConsecutive( testValues, runLength, expectedResult, IS_NOT_LAST_TEST_IN_GROUP); () -> final int[] testValues = { 1, 2, 2, 1, 1, 2, 2, 1 } } final int runLength = -3; final boolean expectedResult = false; 387 doTestHas NConsecutive( testValues, runLength, expectedResult, IS_LAST_TEST_IN_GROUP); ); // end assertall } // end testHas Consecutive() // end class NConsecutive MRTests }
  • Step by Step Solution

    There are 3 Steps involved in it

    Step: 1

    blur-text-image

    Get Instant Access to Expert-Tailored Solutions

    See step-by-step solutions with expert insights and AI powered tools for academic success

    Step: 2

    blur-text-image

    Step: 3

    blur-text-image

    Ace Your Homework with AI

    Get the answers you need in no time with our AI-driven, step-by-step assistance

    Get Started

    Recommended Textbook for

    More Books

    Students also viewed these Databases questions