Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Sample Test Results. Note some of the testing files are not for this question, so just ignore them Main: package cp213; /** * Sample tests

image text in transcribed

Sample Test Results.

image text in transcribed

Note some of the testing files are not for this question, so just ignore them

Main:

package cp213;

/** * Sample tests for the Assignment 1 class methods. Not comprehensive - add your * own testing. * * @author Your name and id here * @version 2022-01-08 */ public class A01Main { // Constants private static final String LINE = "-".repeat(40); private static final String TEST_LINE = "=".repeat(80);

public static final String CIPHERTEXT = "AVIBROWNZCEFGHJKLMPQSTUXYD"; // for testing substitute method

public static void main(String[] args) { System.out.println("Assignment 1 Methods Tests"); System.out.println(); System.out.println("Tests are of the form:"); System.out.println(" Test Operation {expected value}: actual value"); System.out.println();

testIsLeapYear(); testIsPalindrome(); testIsValid(); testPigLatin(); testClosest(); testSumPartialHarmonic(); testAllDigits(); testValidSn(); testIsPrime(); testShift(); testSubstitute(); }

/** * Test isLeapYear. */ private static void testIsLeapYear() { System.out.println(TEST_LINE); System.out.println("Testing isLeapYear"); System.out.println(LINE);

int year = 1900; boolean result = LeapYear.isLeapYear(year); System.out.println("" + year + " {false}: " + result); year = 1996; result = LeapYear.isLeapYear(year); System.out.println("" + year + " {true}: " + result); year = 1999; result = LeapYear.isLeapYear(year); System.out.println("" + year + " {false}: " + result); year = 2000; result = LeapYear.isLeapYear(year); System.out.println("" + year + " {true}: " + result); System.out.println(); }

/** * Test isPalindrome. */ private static void testIsPalindrome() { System.out.println(TEST_LINE); System.out.println("Testing isPalindrome"); System.out.println(LINE);

String string = "a"; boolean result = Strings.isPalindrome(string); System.out.println("" + string + " {true}: " + result); string = "racecar"; result = Strings.isPalindrome(string); System.out.println("" + string + " {true}: " + result); string = "A man, a plan, a canal, Panama!"; result = Strings.isPalindrome(string); System.out.println("" + string + " {true}: " + result); string = "David"; result = Strings.isPalindrome(string); System.out.println("" + string + " {false}: " + result); System.out.println(); }

/** * Test isValid. */ private static void testIsValid() { System.out.println(TEST_LINE); System.out.println("Testing isValid"); System.out.println(LINE);

String string = "a"; boolean result = Strings.isValid(string); System.out.println("" + string + " {true}: " + result); string = "_a"; result = Strings.isValid(string); System.out.println("" + string + " {true}: " + result); string = "1a"; result = Strings.isValid(string); System.out.println("" + string + " {false}: " + result); System.out.println(); }

/** * Test pigLatin. */ private static void testPigLatin() { System.out.println(TEST_LINE); System.out.println("Testing pigLatin"); System.out.println(LINE);

String string = "David"; String result = Strings.pigLatin(string); System.out.println("" + string + " {Avidday}: " + result); string = "arrow"; result = Strings.pigLatin(string); System.out.println("" + string + " {arrowway}: " + result); string = "yard"; result = Strings.pigLatin(string); System.out.println("" + string + " {ardyay}: " + result); System.out.println(); }

/** * Test closest. */ private static void testClosest() { System.out.println(TEST_LINE); System.out.println("Testing closest"); System.out.println(LINE);

double target = 0; double v1 = -5; double v2 = 5; double result = Numbers.closest(target, v1, v2); System.out.println("" + target+", " + v1 +", " + v2 + " {-5.0}: " + result); target = 0; v1 = -10; v2 = 5; result = Numbers.closest(target, v1, v2); System.out.println("" + target+", " + v1 +", " + v2 + " {5.0}: " + result); System.out.println(); }

/** * Test isPrime. */ private static void testIsPrime() { System.out.println(TEST_LINE); System.out.println("Testing isPrime"); System.out.println(LINE);

int n = 7; boolean result = Numbers.isPrime(n); System.out.println("" + n + " {true}: " + result); n = 5; result = Numbers.isPrime(n); System.out.println("" + n + " {true}: " + result); n = 9; result =Numbers.isPrime(n); System.out.println("" + n + " {false}: " + result); System.out.println(); }

/** * Test sumPartialHarmonic. */ private static void testSumPartialHarmonic() { System.out.println(TEST_LINE); System.out.println("Testing sumPartialHarmonic"); System.out.println(LINE);

int n = 0; double result = Numbers.sumPartialHarmonic(n); System.out.println("" + n+ " {0.0}: " + result); n = 1; result = Numbers.sumPartialHarmonic(n); System.out.println("" + n+ " {1.0}: " + result); n = 8; result = Numbers.sumPartialHarmonic(n); System.out.println("" + n+ " {2.7178571428571425}: " + result); System.out.println(); }

/** * Test allDigits. */ private static void testAllDigits() { System.out.println(TEST_LINE); System.out.println("Testing allDigits"); System.out.println(LINE);

String string = "a"; boolean result = SerialNumber.allDigits(string); System.out.println("" + string + " {false}: " + result); string = "123"; result = SerialNumber.allDigits(string); System.out.println("" + string + " {true}: " + result); string = "12.3"; result = SerialNumber.allDigits(string); System.out.println("" + string + " {false}: " + result); System.out.println(); }

/** * Test validSn. */ private static void testValidSn() { System.out.println(TEST_LINE); System.out.println("Testing validSn"); System.out.println(LINE);

String string = "SN/1234-567"; boolean result = SerialNumber.validSn(string); System.out.println("" + string + " {true}: " + result); string = "SN/1234567"; result = SerialNumber.validSn(string); System.out.println("" + string + " {false}: " + result); string = "SN/123-4567"; result = SerialNumber.validSn(string); System.out.println("" + string + " {false}: " + result); System.out.println(); }

/** * Test shift. */ private static void testShift() { System.out.println(TEST_LINE); System.out.println("Testing shift"); System.out.println(LINE);

String string = "ABC"; String result = Cipher.shift(string, 0); System.out.println("" + string + " {ABC}: " + result); string = "ABC"; result = Cipher.shift(string, 3); System.out.println("" + string + " {DEF}: " + result); string = "ABC"; result = Cipher.shift(string, 30); System.out.println("" + string + " {EFG}: " + result); System.out.println(); } /** * Test substitute. */ private static void testSubstitute() { System.out.println(TEST_LINE); System.out.println("Testing substitute"); System.out.println(LINE);

String string = "ABC"; String result = Cipher.substitute(string, CIPHERTEXT); System.out.println("" + string + " {AVI}: " + result); string = "XYZ"; result = Cipher.substitute(string, CIPHERTEXT); System.out.println("" + string + " {XYD}: " + result); System.out.println(); }

}

public class Numbers { /** * Determines closest value of two values to a target value. * @param target the target value @param vi first comparison value * @param v2 second comparison value * @return one of v1 or v2 that is closest to target, vi is the value chosen if vi and v2 are an equal distance from target */ public static double closest(final double target, final double vi, final double v2) { * // your code here return 0.0; } /** * * Determines if n is a prime number. Prime numbers are whole numbers greater * than 1, that have only two factors " 1 and the number itself. Prime numbers * are divisible only by the number 1 or itself. @param n an integer * @return true if n is prime, false otherwise */ public static boolean isPrime(final int n) { * // your code here return false; } * /** * Sums and returns the total of a partial harmonis series. This series is the sum of all terms 1/i, where i ranges from 1 to n (inclusive). Ex: * n = 3: sum = 1/1 + 1/2 + 1/3 = 1.8333333333333333 * @param n an integer * @return sum of partial harmonis series from 1 ton */ public static double sumPartialHarmonic(final int n) { // your code here return 0.0; } } Assigt 1 Methods Tests Tests are of the for: Test Operation (expected value actual value Testing islespear 1980 (false): false 1996 true true 1999 false false 2980 (true): true Testing IsPalindrome a true true racecar true true Asan, a plan, a canal, Panama! (true): true David [false): false Testing isvalid a true true a (true): true ia (false): false Testing pigLatin David Avidday) Avidday arrow Carroi arrow yard ardyay) andyay Testing closest 2.2, -5.2, 5.a 1-5.6): -5.6 2.8, -18., 5. (5.0): 5.8 Testing supartialarmonic @fe.e): 2.0 1 (1.0): 1.a 8 [2.7178571428571425): 2.7178571428571425 Testing allDigits a false false 123 (tre): true 12.3 (false): false Testing valide SN/1234-567 (true true SN/1234567 (false): false SN/123-4567 (false): false Testing Prime 7 true): true s true true 9 false false Testing shift ABC (ABC) ABC ABC DEF): DEF ABC EFG) : ERG Testing Substitute ABC AVI): AVI XYZ XYD): XYD

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_2

Step: 3

blur-text-image_3

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

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

Students also viewed these Databases questions