ByteUtlTest.java 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. XOWA: the XOWA Offline Wiki Application
  3. Copyright (C) 2012-2021 gnosygnu@gmail.com
  4. XOWA is licensed under the terms of the General Public License (GPL) Version 3,
  5. or alternatively under the terms of the Apache License Version 2.0.
  6. You may use XOWA according to either of these licenses as is most appropriate
  7. for your project on a case-by-case basis.
  8. The terms of each license can be found in the source code repository:
  9. GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
  10. Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
  11. */
  12. package gplx.objects.primitives;
  13. import gplx.frameworks.tests.GfoTstr;
  14. import gplx.types.basics.utls.ByteUtl;
  15. import org.junit.Test;
  16. public class ByteUtlTest {
  17. @Test public void int_() {
  18. tst_int_( 0, 0);
  19. tst_int_( 127, 127);
  20. tst_int_( 128, 128); // NOTE: JAVA defines byte as -128 -> 127
  21. tst_int_( 255, 255);
  22. tst_int_( 256, 0); // NOTE: 256 will cast to 1; (byte)256 works same in both JAVA/.NET
  23. } void tst_int_(int v, int expd) {GfoTstr.Eq((byte)expd, ByteUtl.ByInt(v));} // WORKAROUND/JAVA: expd is of type int b/c java promotes numbers to ints
  24. @Test public void To_int() {
  25. tst_XtoInt( 0, 0);
  26. tst_XtoInt( 127, 127);
  27. tst_XtoInt( 128, 128);
  28. tst_XtoInt( 255, 255);
  29. tst_XtoInt( 256, 0);
  30. } void tst_XtoInt(int v, int expd) {GfoTstr.Eq(expd, ByteUtl.ToInt((byte)v));} // WORKAROUND/JAVA: v is of type int b/c java promotes numbers to ints
  31. }