Android Open Source - bin.calc_android Base Converter Test






From Project

Back to project page bin.calc_android.

License

The source code is released under:

GNU General Public License

If you think the Android project bin.calc_android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package info.ohgita.android.bincalc.calculator;
/*  w  w  w .j  av  a  2  s  . co m*/
import junit.framework.TestCase;

public class BaseConverterTest extends TestCase {
  public void testConv() throws Exception {
    BaseConverter bcon = new BaseConverter();
    
    /* Reverse bits */
    assertEquals("1", bcon.reverseBits("0"));
    assertEquals("0101", bcon.reverseBits("1010"));
    
    /* Add bits */
    assertEquals("1", bcon.add1ToBits("0"));
    assertEquals("1001", bcon.add1ToBits("1000"));
    assertEquals("1010", bcon.add1ToBits("1001"));
    
    /* Convert - Positive number */
    // Dec to Bin
    assertEquals("010000000000.1", bcon.decToN(1024.5, 2));
    // Dec to Hex
    assertEquals("400.8", bcon.decToN(1024.5, 16));
    assertEquals("2A", bcon.decToN(42, 16));
    // Bin to Dec
    assertEquals(1024.5, bcon.binToDec("010000000000.1"));
    // Hex to Dec
    assertEquals(1024.5, bcon.hexToDec("400.8"));
    // Bin to Hex
    assertEquals("EE", bcon.decToN(bcon.binToDec("11101110"), 16));
    
    /* Convert - Negative number */
    // Dec to Bin
    assertEquals("11101110", bcon.decToN(-18, 2));
    assertEquals("10000000", bcon.decToN(-128, 2));
    // Dec to hex
    assertEquals("EE", bcon.decToN(-18, 16));
    assertEquals("80", bcon.decToN(-128, 16));
  }
}




Java Source Code List

info.ohgita.android.bincalc.Activity_appInfo.java
info.ohgita.android.bincalc.Activity_main.java
info.ohgita.android.bincalc.Activity_preference.java
info.ohgita.android.bincalc.Adapter_BaseinputsViewPager.java
info.ohgita.android.bincalc.CalculatorBaseConvResult.java
info.ohgita.android.bincalc.CalculatorMemoryData.java
info.ohgita.android.bincalc.Calculator.java
info.ohgita.android.bincalc.Fragment_main.java
info.ohgita.android.bincalc.calculator.BaseConverterTest.java
info.ohgita.android.bincalc.calculator.BaseConverter.java
info.ohgita.android.bincalc.calculator.BasicArithOperator.java
info.ohgita.android.bincalc.calculator.ExpParserTest.java
info.ohgita.android.bincalc.calculator.ExpParser.java
info.ohgita.android.bincalc.calculator.HistoryItem.java