Question: Tests: // Public tests for Lab08 Quadrant enumeration import org.junit.Assert; import static org.junit.Assert.*; // import static org.junit.*; import org.junit.BeforeClass; import org.junit.Before; import org.junit.After; import org.junit.Test;

Tests:
// Public tests for Lab08 Quadrant enumeration import org.junit.Assert; import static org.junit.Assert.*; // import static org.junit.*; import org.junit.BeforeClass; import org.junit.Before; import org.junit.After; import org.junit.Test; import java.io.*; import java.util.*;
public class Lab7Tests { /*Main method runs tests in this file*/ public static void main(String args[]) { org.junit.runner.JUnitCore.main("Lab7Tests"); }
static ByteArrayOutputStream localOut, localErr; static PrintStream sysOut, sysErr; static String [] empty = {};
// Determine what the newline is on the running system String newline = System.getProperty("line.separator");
@BeforeClass public static void setUp() throws Exception { sysOut = System.out; sysErr = System.err; }
// Before every test is run, reset the streams to capture // stdout/stderr @Before public void setUpStreams() { localOut = new ByteArrayOutputStream(); localErr = new ByteArrayOutputStream(); System.setOut(new PrintStream(localOut)); System.setErr(new PrintStream(localErr)); }
// After every test, restore stdout/stderr @After public void cleanUpStreams() { System.setOut(null); System.setErr(null); System.setOut(sysOut); System.setErr(sysErr); } @Test public void SignumsExist() { Signum s; s = Signum.POS; s = Signum.ZERO; s = Signum.NEG; } @Test public void signums_only3() { assertEquals(3, Signum.values().length); } @Test public void signums_str_pos () { assertEquals("+",Signum.POS .toString()); } @Test public void signums_str_zero() { assertEquals("0",Signum.ZERO.toString()); } @Test public void signums_str_neg () { assertEquals("-",Signum.NEG .toString()); } @Test public void QuadrantsExist() { Quadrant q; q = Quadrant.Q1; q = Quadrant.Q2; q = Quadrant.Q3; q = Quadrant.Q4; q = Quadrant.NONE; }
@Test public void quadrants_only5() { assertEquals(5, Quadrant.values().length); }
@Test public void flipX_1(){ assertEquals(Quadrant.Q1.flipX(), Quadrant.Q2); } @Test public void flipX_2(){ assertEquals(Quadrant.Q2.flipX(), Quadrant.Q1); } @Test public void flipX_3(){ assertEquals(Quadrant.Q3.flipX(), Quadrant.Q4); } @Test public void flipX_4(){ assertEquals(Quadrant.Q4.flipX(), Quadrant.Q3); } @Test public void flipX_NONE(){ assertEquals(Quadrant.NONE.flipX(), Quadrant.NONE); }
@Test public void flipY_all(){ assertEquals(Quadrant.Q1.flipY(), Quadrant.Q4); assertEquals(Quadrant.Q4.flipY(), Quadrant.Q1); assertEquals(Quadrant.Q3.flipY(), Quadrant.Q2); assertEquals(Quadrant.Q2.flipY(), Quadrant.Q3); assertEquals(Quadrant.NONE.flipY(), Quadrant.NONE); }
@Test public void signPair_1(){ assertEquals(Quadrant.Q1.signPair(), "(+,+)"); } @Test public void signPair_2(){ assertEquals(Quadrant.Q2.signPair(), "(-,+)"); } @Test public void signPair_3(){ assertEquals(Quadrant.Q3.signPair(), "(-,-)"); } @Test public void signPair_4(){ assertEquals(Quadrant.Q4.signPair(), "(+,-)"); } @Test public void signPair_none(){ assertEquals(Quadrant.NONE.signPair(), "(?,?)"); }
@Test public void fromInts_all(){ assertEquals( Quadrant.Q1, Quadrant.fromInts( 1, 5)); assertEquals( Quadrant.Q1, Quadrant.fromInts( 12, 2)); assertEquals( Quadrant.Q2, Quadrant.fromInts( -1, 5)); assertEquals( Quadrant.Q2, Quadrant.fromInts(-13, 16)); assertEquals( Quadrant.Q3, Quadrant.fromInts(-12, -4)); assertEquals( Quadrant.Q3, Quadrant.fromInts( -5, -1)); assertEquals( Quadrant.Q4, Quadrant.fromInts( 13,-52)); assertEquals( Quadrant.Q4, Quadrant.fromInts( 91, -2)); assertEquals( Quadrant.NONE, Quadrant.fromInts( 0, 1)); assertEquals( Quadrant.NONE, Quadrant.fromInts( 0, -2)); assertEquals( Quadrant.NONE, Quadrant.fromInts( 3, 0)); assertEquals( Quadrant.NONE, Quadrant.fromInts( -4, 0)); assertEquals( Quadrant.NONE, Quadrant.fromInts( 0, 0)); }
public void test_main(String argS, String expect){ setUpStreams(); String args[] = argS.split("\\s+"); Quadrant.main(args); String actual = localOut.toString(); String msg = String.format(" Arguments: %s Expect: %s Actual: %s ", argS,expect,actual); assertEquals(msg, expect, actual); cleanUpStreams(); }
@Test public void main_1(){ test_main("", ""); } @Test public void main_2(){ test_main("1", ""); } @Test public void main_3(){ test_main("-1", ""); } @Test public void main_4(){ test_main("1 5", "(1,5) has signs (+,+) and is in Q1"+newline+ ""); } @Test public void main_5(){ test_main("-2 -13 4", "(-2,-13) has signs (-,-) and is in Q3"+newline+ ""); } @Test public void main_6(){ test_main("0 5 10 0", "(0,5) has signs (?,?) and is in NONE"+newline+ "(10,0) has signs (?,?) and is in NONE"+newline+ ""); } @Test public void main_7(){ test_main("2 -13 4 12 -1 113 19", "(2,-13) has signs (+,-) and is in Q4"+newline+ "(4,12) has signs (+,+) and is in Q1"+newline+ "(-1,113) has signs (-,+) and is in Q2"+newline+ ""); } @Test public void main_8(){ test_main("1 2 -3 -4 5 -6 -7 -8 9 10 11 -12 -13 14 -15 -16 17 18 -19 20", "(1,2) has signs (+,+) and is in Q1"+newline+ "(-3,-4) has signs (-,-) and is in Q3"+newline+ "(5,-6) has signs (+,-) and is in Q4"+newline+ "(-7,-8) has signs (-,-) and is in Q3"+newline+ "(9,10) has signs (+,+) and is in Q1"+newline+ "(11,-12) has signs (+,-) and is in Q4"+newline+ "(-13,14) has signs (-,+) and is in Q2"+newline+ "(-15,-16) has signs (-,-) and is in Q3"+newline+ "(17,18) has signs (+,+) and is in Q1"+newline+ "(-19,20) has signs (-,+) and is in Q2"+newline+ ""); } }
3 SIGNuM ENUMERATION Values A signum represents one of three possible states: NEG, zERo, pos. Represent these three values and no others. Fields/Constructors none required, but you are welcome to add some if you see fit. Methods public string tostring). Returns one of these strings as appropriate: "+"."o","-". Hint: using a switch statement on this is a common useful trick when writing methods over enumerations. 4 QUADRANT ENUMERATION Values There are five elements of the Quadrant enumeration: Q1, 02, Q3, 04, NONE. Ensure that these are all present and no other exist. Fields Each Quadrant needs to know if its x and y components are positive, zero, or negative. Use your signum type internally (private field) we can' check this directly, but you'll need this exact information for the methods below. Methods private Quadrant (signum xsig, signum ysig). We can't test your private constructor, but use this chance to fill in your private fields. Note: the NONE value should represent all coordinates on either/both axes; store null as its xSig and ySig values public boolean xPositive). Does this quadrant have a positivex? public boolean ypositiDoes this quadrant have a negative x? public String signPair). Return a string of the format "(+-", which shows the String representations of the xSig and ySig fields (as shown below)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
