X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Ftest%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2FDigestUnitTest.java;fp=app%2Fsrc%2Ftest%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2FDigestUnitTest.java;h=4c0dc15f59533e4b46f11e725a94bd53b8edeaa9;hp=0000000000000000000000000000000000000000;hb=7ed8a95a1c23142109a3f2cfcc95f34869aee01c;hpb=a983099d6150044a08a1fbc601d9af9bd8d0c0a8
diff --git a/app/src/test/java/net/ktnx/mobileledger/DigestUnitTest.java b/app/src/test/java/net/ktnx/mobileledger/DigestUnitTest.java
new file mode 100644
index 00000000..4c0dc15f
--- /dev/null
+++ b/app/src/test/java/net/ktnx/mobileledger/DigestUnitTest.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright © 2018 Damyan Ivanov.
+ * This file is part of Mobile-Ledger.
+ * Mobile-Ledger is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * Mobile-Ledger is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mobile-Ledger. If not, see .
+ */
+
+package net.ktnx.mobileledger;
+
+import net.ktnx.mobileledger.utils.Digest;
+
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertEquals;
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * @see Testing documentation
+ */
+public class DigestUnitTest {
+ @Test
+ public void digestToHexString_isCorrect() {
+ assertEquals('0', Digest.hexDigitFor(0));
+ assertEquals('1', Digest.hexDigitFor(1));
+ assertEquals('2', Digest.hexDigitFor(2));
+ assertEquals('3', Digest.hexDigitFor(3));
+ assertEquals('4', Digest.hexDigitFor(4));
+ assertEquals('5', Digest.hexDigitFor(5));
+ assertEquals('6', Digest.hexDigitFor(6));
+ assertEquals('7', Digest.hexDigitFor(7));
+ assertEquals('8', Digest.hexDigitFor(8));
+ assertEquals('9', Digest.hexDigitFor(9));
+ assertEquals('a', Digest.hexDigitFor(10));
+ assertEquals('b', Digest.hexDigitFor(11));
+ assertEquals('c', Digest.hexDigitFor(12));
+ assertEquals('d', Digest.hexDigitFor(13));
+ assertEquals('e', Digest.hexDigitFor(14));
+ assertEquals('f', Digest.hexDigitFor(15));
+ }
+ @Test
+ public void hexDigitsFor_isCorrect() {
+ assertEquals("00", String.valueOf(Digest.hexDigitsFor(0)));
+ assertEquals("10", String.valueOf(Digest.hexDigitsFor(16)));
+ assertEquals("ff", String.valueOf(Digest.hexDigitsFor(255)));
+ assertEquals("a0", String.valueOf(Digest.hexDigitsFor(160)));
+ assertEquals("10", String.valueOf(Digest.hexDigitsFor((byte) 16)));
+ assertEquals("ff", String.valueOf(Digest.hexDigitsFor((byte) -1)));
+ }
+ @Test(expected = ArithmeticException.class)
+ public void digestToHexString_throwsOnNegative() {
+ Digest.hexDigitFor(-1);
+ }
+ @Test(expected = ArithmeticException.class)
+ public void digestToHexString_throwsOnGreaterThan15() {
+ Digest.hexDigitFor(16);
+ }
+ @Test(expected = ArithmeticException.class)
+ public void hexDigitsFor_throwsOnNegative() {
+ final char[] chars = Digest.hexDigitsFor(-5);
+ }
+ @Test(expected = ArithmeticException.class)
+ public void hexDigitsFor_throwsOnGreatherThan255() {
+ final char[] chars = Digest.hexDigitsFor(256);
+ }
+}
\ No newline at end of file