public static void main(String[] args) { Calculator c = new Calculator(); c.setSize(300, 300); c.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); c.setVisible(true); c.setResizable(false); }
@Test public void divideで3と2の除算結果が取得できる() { Calculator calc = new Calculator(); float expected = 1.5f; float actual = calc.divide(3, 2); assertThat(actual, is(expected)); }
@Test public void shouldReturnNotANumberIfANumberIsAddedToNotANumberObtainedOnDividingByZero() { Calculator calculator = new Calculator(); calculator.divide(0.0); assertEquals(Double.NaN, calculator.add(4.0), 0.0001); }
@Test public void multiplyで3と4の乗算結果が取得できる() { Calculator calc = new Calculator(); int expected = 12; int actual = calc.multiply(3, 4); assertThat(actual, is(expected)); }
@Test public void shouldReturnOneIfNumberDividesItself() { Calculator calculator = new Calculator(); calculator.add(5.0); assertEquals(1.0, calculator.divide(5.0), 0.0001); }
@Test public void shouldReturnTheNumberItselfIfOneDividesAnyNumber() { Calculator calculator = new Calculator(); calculator.add(5.0); assertEquals(5.0, calculator.divide(1.0), 0.0001); }
/** * Invalid Entry - Start Calculator * * @param jc parent * @param value value * @param format format * @param displayType display type * @param title title * @param operator optional math operator +-/* * @return value */ public static String startCalculator( Container jc, String value, DecimalFormat format, int displayType, String title, char operator) { log.config("Value=" + value); BigDecimal startValue = new BigDecimal(0.0); try { if (value != null && value.length() > 0) { Number number = format.parse(value); startValue = new BigDecimal(number.toString()); } } catch (ParseException pe) { log.info("InvalidEntry - " + pe.getMessage()); } // Find frame Frame frame = Env.getFrame(jc); // Actual Call Calculator calc = new Calculator(frame, title, displayType, format, startValue); if ("*+-/%".indexOf(operator) > -1) calc.handleInput(operator); AEnv.showCenterWindow(frame, calc); BigDecimal result = calc.getNumber(); log.config("Result=" + result); // calc = null; if (result != null) return format.format(result); else return value; // original value } // startCalculator
/** Test the divide method with valid input, negative input, and dividing by zero */ public void testDivide() { // Test valid input try { assertEquals("Method did not divide properly", calc.divide(10, 5), 2); } catch (NegativeArgumentException e) { fail("Method did not divide properly"); } catch (ArithmeticException e) { fail("Method did not divide properly"); } // Test negative input try { calc.divide(-4, 5); fail("Calculator did not throw NegativeArgumentException"); } catch (NegativeArgumentException e) { } catch (ArithmeticException e) { fail("Calculator did not throw NegativeArgumentException"); } // Test divide by zero try { calc.divide(10, 0); fail("Calculator did not throw ArithmeticException"); } catch (NegativeArgumentException e) { fail("Calculator did not throw ArithmeticException"); } catch (ArithmeticException e) { } }
@Test public void shouldReturnTwoIfFiveDividesTen() { Calculator calculator = new Calculator(); calculator.add(10.0); assertEquals(2.0, calculator.divide(5.0), 0.0001); }
@Test public void shouldReturnZeroIfOperationsAreCancelled() { Calculator calculator = new Calculator(); calculator.cancel(); assertEquals(0.0, calculator.cancel(), 0.0001); }
public static void main(String[] args) { Calculator cal = new Calculator(); cal.add(2, 5); cal.substruct(5, 3); cal.div(8, 5); cal.multiple(9, 2); }
@Test public void shouldReturnTwoIfFiveIsSubtractedAfterSevenWasAdded() { Calculator calculator = new Calculator(); calculator.add(7.0); assertEquals(2.0, calculator.subtract(5.0), 0.0001); }
@Test public void shouldReturnFifteenIfThreeIsMultipliedToFive() { Calculator calculator = new Calculator(); calculator.add(5.0); assertEquals(15.0, calculator.multiply(3.0), 0.0001); }
@Test public void shouldReturnNegativeSevenIfFiveIsSubtractedAfterTwoWasSubtracted() { Calculator calculator = new Calculator(); calculator.subtract(2.0); assertEquals(-7.0, calculator.subtract(5.0), 0.0001); }
@Test public void shouldReturnTheNumberToBeAddedIfItIsAddedInitiallySatisfyingTheAdditiveIdentityProperty() { Calculator calculator = new Calculator(); assertEquals(5.0, calculator.add(5.0), 0.0001); }
@Test public void shouldReturnResultSevenIfItFiveIsAddedToNumberTwoWhichWasAddedEarlier() { Calculator calculator = new Calculator(); calculator.add(2.0); assertEquals(7.0, calculator.add(5.0), 0.0001); }
public static PinItem genPinItem(JSONObject pItem) { PinItem pi; try { JSONArray comObj; JSONObject commentObj; Comment comment; pi = new PinItem(); pi.setPinItem(pItem); pi.getImages() .setThumb_loc( Calculator.getFileFromUrl(pItem.optJSONObject(IMAGES).optString(THUMBNAIL))); pi.getImages() .setMob_loc(Calculator.getFileFromUrl(pItem.optJSONObject(IMAGES).optString(MOBILE))); pi.getUser().setJUser(pItem.getJSONObject(USER)); pi.getBoard().setBoard(pItem.getJSONObject(BOARD)); comObj = pItem.optJSONArray(COMMENTS); if (null != comObj) { for (int j = 0; j < comObj.length(); j++) { commentObj = comObj.getJSONObject(j); comment = pi.newComment(commentObj); comment.getUser().setJUser(commentObj.getJSONObject(USER)); pi.getComments().add(comment); } } } catch (JSONException e) { e.printStackTrace(); return null; } finally { System.gc(); } return pi; }
/** Test the subtract method with valid input, negative input, and a negative Result */ public void testSubtract() { // Test normal functionality try { assertEquals("Method did not subtract properly", calc.subtract(5, 4), 1); } catch (NegativeArgumentException e) { fail("Method did not subtract properly"); } catch (NegativeResultException e) { fail("Method did not subtract properly"); } // Test negative input try { calc.subtract(-4, 5); fail("Calculator did not throw NegativeArgumentException"); } catch (NegativeArgumentException e) { } catch (NegativeResultException e) { fail("Calculator did not throw NegativeArgumentException"); } // test a negative result try { calc.subtract(4, 5); fail("Calculator did not throw NegativeResultException"); } catch (NegativeArgumentException e) { fail("Calculator did not throw NegativeResultException"); } catch (NegativeResultException e) { } }
public static void main(String[] args) { Calculator c = new Calculator(); c.plus(10, 20); c.minus(10, 20); // 추가한 기능 사용 c.multiple(10, 20); }
@Test public void multiplyで5と7の乗算結果が取得できる() { Calculator calc = new Calculator(); int expected = 35; int actual = calc.multiply(5, 7); assertThat(actual, is(expected)); }
@Test public void shouldReturnTenIfTwoIsMultipliedToMultiplicationOfFiveAndOne() { Calculator calculator = new Calculator(); calculator.add(1.0); calculator.multiply(5.0); assertEquals(10.0, calculator.multiply(2.0), 0.0001); }
@Test public void shouldReturnTheNumberItselfIfOneIsMultipliedToAnyNumberSatisfyingMultiplicativeIdentity() { Calculator calculator = new Calculator(); calculator.add(5.0); assertEquals(5.0, calculator.multiply(1.0), 0.0001); }
@Test public void shouldReturnTwoIfFiveDividesTenWhichIsObtainedOnDividingTwentyByTwo() { Calculator calculator = new Calculator(); calculator.add(20.0); calculator.divide(2.0); assertEquals(2.0, calculator.divide(5.0), 0.0001); }
@Test public void getInterface() throws ScriptException { engine.eval("calculate <- function(x) sqrt(x)"); Calculator calculator = invocableEngine.getInterface(Calculator.class); assertThat(calculator.calculate(64), equalTo(8d)); }
public static void main(String[] args) { Calculator c = new Calculator(); for (int i = 0; i < args.length; i++) { c.execute(args[i]); } }
@Test public void shouldReturnTheNumberIfTheNumberIsAddedAfterOperationsAreCancelled() { Calculator calculator = new Calculator(); calculator.add(5.0); calculator.cancel(); assertEquals(5.0, calculator.add(5.0), 0.0001); }
@Test public void shouldBeAbleToExitTheApplicationOnExit() { exit.expectSystemExitWithStatus(0); Calculator calculator = new Calculator(); calculator.add(5.0); calculator.exit(); }
@Override public void undo() { c.setDisplay(display); // Set correct operator if one is found if (findOperatorNdx() != -1) c.setOperator(display.charAt(findOperatorNdx())); else { c.setOperator(' '); } }
public static void main(String[] args) throws ParseException, TokenMgrError { Calculator calc = new Calculator(System.in); try { calc.start(); System.out.println("sucesso!"); } catch (Exception e) { System.out.println("Nao sucesso"); } }
public void setCopy(String val) { copyCalc.viewStr = val; copyCalc.tokens = new ArrayList<CalcItem>(); copyCalc.tokenLens = new ArrayList<Integer>(); for (int i = 0; i < val.length(); i += 1) { copyCalc.tokens.add(new ComplexNumberStr(val.substring(i, i + 1))); copyCalc.tokenLens.add(1); } copyCalc.viewIndex = val.length(); }