Esempio n. 1
0
 @Test
 public void multiplyで3と4の乗算結果が取得できる() {
   Calculator calc = new Calculator();
   int expected = 12;
   int actual = calc.multiply(3, 4);
   assertThat(actual, is(expected));
 }
Esempio n. 2
0
 @Test
 public void divideで3と2の除算結果が取得できる() {
   Calculator calc = new Calculator();
   float expected = 1.5f;
   float actual = calc.divide(3, 2);
   assertThat(actual, is(expected));
 }
Esempio n. 3
0
 @Test
 public void multiplyで5と7の乗算結果が取得できる() {
   Calculator calc = new Calculator();
   int expected = 35;
   int actual = calc.multiply(5, 7);
   assertThat(actual, is(expected));
 }
Esempio n. 4
0
 // TASK 1: WRITE JUNIT TESTS
 // YOUR CODE HERE
 @Test
 public void testAddition() {
   int res;
   res = tester.add(1503, 1230);
   assertEquals(2733, res);
   res = tester.add(-1503, 1230);
   assertEquals(-273, res);
   res = tester.add(1503, -1230);
   assertEquals(273, res);
 }
Esempio n. 5
0
 @Test
 public void testMultiplation() {
   int res;
   res = tester.multiply(153, 123);
   assertEquals(18819, res);
   res = tester.multiply(-153, 123);
   assertEquals(-18819, res);
   res = tester.multiply(153, -123);
   assertEquals(-18819, res);
 }
Esempio n. 6
0
  @Test
  public void testSubtract() {
    Calculator calc = new Calculator();

    assertEquals(calc.getTotal(), 0);

    calc.subtract(-6);
    calc.subtract(4);

    // The total value should be 2 after subtracting -6 and 4 from 0
    assertEquals(calc.getTotal(), 2);
  }
Esempio n. 7
0
  @Test
  public void testAdd() {
    Calculator calc = new Calculator();

    // Make sure the total value is 0
    assertEquals(calc.getTotal(), 0);

    calc.add(6);
    calc.add(1);

    // The total value should be 7 after adding 6 and 1 to 0
    assertEquals(calc.getTotal(), 7);
  }
Esempio n. 8
0
  @Test
  public void test() {
    // fail("Not yet implemented");

    int data = obj.calculate(3, 24);
    assertEquals(data, 27);
    assertNotNull(data);
  }
  @Test
  public void 単純な四則演算検証() {

    // (10 + 2 - 4) * 4 / 8 = 4
    assertThat(Calculator.of(10).add(2).subtract(4).multiply(4).divideBy(8).intValue(), is(4));

    // (12.4 + 0.033 - 2.33) * 0.3 / 3.3 = 0.91 (RoundingMode.DOWN)
    assertThat(
        Calculator.of(12.4)
            .scale(2)
            .add(0.033)
            .subtract(2.33)
            .multiply(0.3)
            .divideBy(3.3)
            .decimal(),
        is(new BigDecimal("0.91")));
  }
  @Test
  public void testSquare() {
    int input = 4;
    int expected = 16;

    int actual = calc.square(input);
    assertEquals(expected, actual);
  }
  @Test
  public void 累積端数処理の検証() {

    // 3.333 -> 3.334 -> 3.335 (= 3.34)
    assertThat(
        Calculator.of(3.333).scale(2, RoundingMode.HALF_UP).add(0.001).add(0.001).decimal(),
        is(new BigDecimal("3.34")));

    // 3.333 -> 3.330 -> 3.330 (= 3.33)
    assertThat(
        Calculator.of(3.333)
            .scale(2, RoundingMode.HALF_UP)
            .roundingAlways(true)
            .add(0.001)
            .add(0.001)
            .decimal(),
        is(new BigDecimal("3.33")));
  }
Esempio n. 12
0
  @Test
  public void testGetHistory() {
    Calculator calc = new Calculator();

    assertEquals(calc.getHistory(), "" + 0);

    calc.add(14);
    calc.divide(2);
    calc.multiply(3);
    calc.subtract(6);

    // Testing the history method
    assertEquals("0 + 14 / 2 * 3 - 6", calc.getHistory());
  }
  @Test
  public void testReturnDigitsOnly() throws KettleException {
    RowMeta inputRowMeta = new RowMeta();
    ValueMetaString nameMeta = new ValueMetaString("Name");
    inputRowMeta.addValueMeta(nameMeta);
    ValueMetaString valueMeta = new ValueMetaString("Value");
    inputRowMeta.addValueMeta(valueMeta);

    RowSet inputRowSet =
        smh.getMockInputRowSet(new Object[][] {{"name1", "qwe123asd456zxc"}, {"name2", null}});
    inputRowSet.setRowMeta(inputRowMeta);

    Calculator calculator =
        new Calculator(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    calculator.getInputRowSets().add(inputRowSet);
    calculator.setInputRowMeta(inputRowMeta);
    calculator.init(smh.initStepMetaInterface, smh.initStepDataInterface);

    CalculatorMeta meta = new CalculatorMeta();
    meta.setCalculation(
        new CalculatorMetaFunction[] {
          new CalculatorMetaFunction(
              "digits",
              CalculatorMetaFunction.CALC_GET_ONLY_DIGITS,
              "Value",
              null,
              null,
              ValueMetaInterface.TYPE_STRING,
              0,
              0,
              false,
              "",
              "",
              "",
              "")
        });

    // Verify output
    try {
      calculator.addRowListener(
          new RowAdapter() {
            @Override
            public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row)
                throws KettleStepException {
              assertEquals("123456", row[2]);
            }
          });
      calculator.processRow(meta, new CalculatorData());
    } catch (KettleException ke) {
      ke.printStackTrace();
      fail();
    }
  }
Esempio n. 14
0
  @Test
  public void testGetTotal() {
    Calculator calc = new Calculator();

    calc.add(4);
    calc.subtract(1);
    calc.multiply(6);
    calc.divide(3);

    // The total value should be 6
    assertEquals(calc.getTotal(), 6);
  }
Esempio n. 15
0
  @Test
  public void testMultiply() {
    Calculator calc = new Calculator();

    calc.multiply(10);

    assertEquals(calc.getTotal(), 0);

    calc.add(2);
    calc.multiply(7);

    // The total value should be 14 after adding 2 to 0 then multiplying by 7
    assertEquals(calc.getTotal(), 14);
  }
Esempio n. 16
0
  @Test
  public void testDivide() {
    Calculator calc = new Calculator();

    calc.divide(0);

    // Testing dividing by 0
    assertEquals(calc.getTotal(), 0);

    calc.add(12);
    calc.divide(6);

    // The total value should be 2 after adding 12 then dividing by 6
    assertEquals(calc.getTotal(), 2);
  }
  @Test
  public void calculatorShouldClearDataInstance() throws Exception {
    RowMeta inputRowMeta = new RowMeta();
    ValueMetaInteger valueMeta = new ValueMetaInteger("Value");
    inputRowMeta.addValueMeta(valueMeta);

    RowSet inputRowSet = smh.getMockInputRowSet(new Object[] {-1L});
    inputRowSet.setRowMeta(inputRowMeta);

    Calculator calculator =
        new Calculator(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    calculator.getInputRowSets().add(inputRowSet);
    calculator.setInputRowMeta(inputRowMeta);
    calculator.init(smh.initStepMetaInterface, smh.initStepDataInterface);

    CalculatorMeta meta = new CalculatorMeta();
    meta.setCalculation(
        new CalculatorMetaFunction[] {
          new CalculatorMetaFunction(
              "test",
              CalculatorMetaFunction.CALC_ABS,
              "Value",
              null,
              null,
              ValueMetaInterface.TYPE_STRING,
              0,
              0,
              false,
              "",
              "",
              "",
              "")
        });

    CalculatorData data = new CalculatorData();
    data = spy(data);

    calculator.processRow(meta, data);
    verify(data).getValueMetaFor(eq(valueMeta.getType()), anyString());

    calculator.processRow(meta, data);
    verify(data).clearValuesMetaMapping();
  }
Esempio n. 18
0
 @Test
 public void testAdd() {
   calculator.add(2);
   calculator.add(3);
   assertEquals(5, calculator.getResult());
 }
 @Test
 public void graterThan1000isIgnored() throws Exception {
   assertEquals(calculator.calculate("1,1,1001"), 2);
 }
 @Test(expected = Exception.class)
 public void negativeReturnsException() throws Exception {
   calculator.calculate("-1");
 }
 @Test
 public void threeNumbersDelimitedBothWayReturnsSum() throws Exception {
   assertEquals(calculator.calculate("1,2,3"), 6);
 }
 @Test
 public void twoNumbersNewLineDelimitedReturnSum() throws Exception {
   assertEquals(calculator.calculate("1\n2"), 3);
 }
 @Test
 public void twoNumbersReturnsSum() throws Exception {
   assertEquals(calculator.calculate("1,2"), 3);
 }
 @Test
 public void singleValueIsReplied() throws Exception {
   assertEquals(calculator.calculate("1"), 1);
 }
Esempio n. 25
0
 @Test
 public void testSubstract() {
   calculator.add(10);
   calculator.substract(2);
   assertEquals(8, calculator.getResult());
 }
Esempio n. 26
0
 @Test(timeout = 1000)
 public void testSquareRoot() {
   calculator.squareRoot(4);
   assertEquals(2, calculator.getResult());
 }
Esempio n. 27
0
 @Test
 public void testDivide() {
   calculator.add(8);
   calculator.divide(2);
   assertEquals(4, calculator.getResult());
 }
 @Test
 public void emptyStringReturnsZero() throws Exception {
   assertEquals(calculator.calculate(""), 0);
 }
Esempio n. 29
0
 @Before
 public void setUp() throws Exception {
   calculator.clear();
 }
Esempio n. 30
0
 @Test(expected = IllegalArgumentException.class)
 public void divideで5と0のときIllegalArgumentExceptionを送出する() {
   Calculator calc = new Calculator();
   calc.divide(5, 0);
 }