Example:
Feature: Convert between different currencies Scenario: Convert SGD to CNY Given currency:"SGD", amount:10 Given fxRate is 4.60 When convert to "CNY" Then the result is 46 in CNY
JUnit Test: it can be generated by cucumber plugins, but not perfect for my IDE. (cannot generate all steps, but you still can copy the generated JUnit code from the output)
package com.liguoliang.bdd; import cucumber.annotation.Before; import cucumber.annotation.en.Given; import cucumber.annotation.en.Then; import cucumber.annotation.en.When; import org.junit.Assert; import java.math.BigDecimal; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** * Created by guoliang on 3/14/15. */ public class FxConverterTest { private FxConverter fxConverter; @Before public void setUp() { fxConverter = new FxConverter(); } @Given("^currency:\"([^\"]*)\", amount:(\\d+)$") public void currency_amount(String currency, BigDecimal amount) throws Throwable { fxConverter.setCurrencySource(currency); fxConverter.setAmountInput(amount); } @Given("^fxRate is (.+)$") public void fxRate_is_(BigDecimal rate) throws Throwable { fxConverter.setFxRate(rate); } @When("^convert to \"([^\"]*)\"$") public void convert_to(String currency) throws Throwable { fxConverter.convertTo(currency); } @Then("^the result is (.+) in CNY$") public void the_result_is_in_CNY(BigDecimal resultExpected) throws Throwable { assertTrue(resultExpected.compareTo(fxConverter.getAmountResult()) == 0); } }
Two’s complement is the way every computer I know of chooses to represent integers. To get the two’s complement negative notation of an integer, you write out the number in binary. You then invert the digits, and add one to the result.
Integer input = 50; String binString = Integer.toBinaryString(input); BitSet bitSet = BitSet.valueOf(new long[] {input}); for (int i = 0; i < binString.length(); i++) { bitSet.flip(i); } System.out.println(Arrays.toString(bitSet.toByteArray()));
// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.