com.io7m.jbssio.tests.BSSRangeHalfOpenTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.io7m.jbssio.tests Show documentation
Show all versions of com.io7m.jbssio.tests Show documentation
Java bitstream structure I/O (Test suite)
The newest version!
/*
* Copyright © 2019 Mark Raynsford https://www.io7m.com
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
package com.io7m.jbssio.tests;
import com.io7m.jbssio.vanilla.internal.BSSRangeHalfOpen;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.OptionalLong;
public final class BSSRangeHalfOpenTest
{
@Test
public void testRangeOK()
{
final var r = new BSSRangeHalfOpen(0L, OptionalLong.of(0xffff_ffff_ffff_ffffL));
Assertions.assertEquals("[0x0, 0xffffffffffffffff)", r.toString());
Assertions.assertTrue(r.includesValue(0L));
Assertions.assertTrue(r.includesValue(0xffff_ffff_ffff_fffeL));
Assertions.assertFalse(r.includesValue(0xffff_ffff_ffff_ffffL));
}
@Test
public void testRangeOKUnbounded()
{
final var r = new BSSRangeHalfOpen(0L, OptionalLong.empty());
Assertions.assertEquals("[0x0, ∞)", r.toString());
Assertions.assertTrue(r.includesValue(0L));
Assertions.assertTrue(r.includesValue(0xffff_ffff_ffff_ffffL));
}
@Test
public void testRangeInclusion()
{
final var r0 = new BSSRangeHalfOpen(0L, OptionalLong.empty());
final var r1 = new BSSRangeHalfOpen(0L, OptionalLong.empty());
final var r2 = new BSSRangeHalfOpen(0L, OptionalLong.of(0xffff_ffff_ffff_ffffL));
final var r3 = new BSSRangeHalfOpen(0L, OptionalLong.of(0xffff_ffff_ffff_fffeL));
Assertions.assertTrue(r0.isIncludedIn(r1));
Assertions.assertTrue(r1.isIncludedIn(r0));
Assertions.assertTrue(r2.isIncludedIn(r0));
Assertions.assertFalse(r0.isIncludedIn(r2));
Assertions.assertFalse(r0.isIncludedIn(r3));
Assertions.assertTrue(r3.isIncludedIn(r2));
}
@Test
public void testRangeIncludes()
{
final var r = new BSSRangeHalfOpen(0L, OptionalLong.of(10L));
for (var i = 0; i < 10; ++i) {
Assertions.assertTrue(r.includesValue(i));
}
Assertions.assertFalse(r.includesValue(10));
}
@Test
public void testRangeBad0()
{
Assertions.assertThrows(IllegalArgumentException.class, () -> {
new BSSRangeHalfOpen(0xffff_ffff_ffff_ffffL, OptionalLong.of(0L));
});
}
}