ScientificNotation { public long calculate(String number) { if (number == null || !number.contains("E")) { throw new IllegalArgumentException("Invalid format for number " + number); } String[] splittedNumber = splitScientificNumber(number); double first = getLeftPart(splittedNumber[0]); int sign = getNumberSign(splittedNumber[1]); int pow = getPow(splittedNumber[1]); Double result = sign * first * Math.pow(10, pow); return result.longValue(); }  long calculate(String number);  }
@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullStringAsInput() { scientificNotation.calculate(null); }
@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptMalformedScientificNumbers() { scientificNotation.calculate("9.18F+09"); }
@Test public void shouldReturnTheValueOfTheNumber() { String number = "9.18E+09"; long result = scientificNotation.calculate(number); assertEquals(9180000000L, result); }
@Test public void shouldTakeIntoAccountNegativeNumbers() { String number = "-9.18E+09"; long result = scientificNotation.calculate(number); assertEquals(-9180000000L, result); }