use of org.testng.Assert in project gatk by broadinstitute.
the class CreatePanelOfNormalsIntegrationTest method assertRamPoNDuplicate.
/**
* Assert that we can create a valid ram pon duplicate.
*
* @param pon never {@code null}
*/
private void assertRamPoNDuplicate(final PCACoveragePoN pon) {
final PCACoveragePoN ramPoN = new RamPCACoveragePoN(pon);
PoNTestUtils.assertEqualsMatrix(pon.getLogNormalizedCounts(), ramPoN.getLogNormalizedCounts(), false);
PoNTestUtils.assertEqualsMatrix(pon.getLogNormalizedPInverseCounts(), ramPoN.getLogNormalizedPInverseCounts(), false);
PoNTestUtils.assertEqualsMatrix(pon.getNormalizedCounts(), ramPoN.getNormalizedCounts(), false);
PoNTestUtils.assertEqualsMatrix(pon.getReducedPanelCounts(), ramPoN.getReducedPanelCounts(), false);
PoNTestUtils.assertEqualsMatrix(pon.getReducedPanelPInverseCounts(), ramPoN.getReducedPanelPInverseCounts(), false);
PoNTestUtils.assertEqualsDoubleArrays(pon.getTargetFactors(), ramPoN.getTargetFactors());
final List<Target> ponPanelTargets = pon.getPanelTargets();
final List<Target> ponTargets = pon.getTargets();
final List<Target> ponRawTargets = pon.getRawTargets();
final List<Target> ramPoNPanelTargets = ramPoN.getPanelTargets();
final List<Target> ramPoNTargets = ramPoN.getTargets();
final List<Target> ramPoNRawTargets = ramPoN.getRawTargets();
Assert.assertEquals(ponPanelTargets.size(), ramPoNPanelTargets.size());
Assert.assertEquals(ponTargets.size(), ramPoNTargets.size());
// Make sure every target is the same
Assert.assertTrue(IntStream.range(0, ponRawTargets.size()).boxed().allMatch(i -> ponRawTargets.get(i).equals(ramPoNRawTargets.get(i))));
Assert.assertTrue(IntStream.range(0, ponTargets.size()).boxed().allMatch(i -> ponTargets.get(i).equals(ramPoNTargets.get(i))));
Assert.assertTrue(IntStream.range(0, ponPanelTargets.size()).boxed().allMatch(i -> ponPanelTargets.get(i).equals(ramPoNPanelTargets.get(i))));
// Make sure every sample name is the same
Assert.assertTrue(IntStream.range(0, pon.getSampleNames().size()).boxed().allMatch(i -> pon.getSampleNames().get(i).equals(ramPoN.getSampleNames().get(i))));
Assert.assertTrue(IntStream.range(0, pon.getPanelSampleNames().size()).boxed().allMatch(i -> pon.getPanelSampleNames().get(i).equals(ramPoN.getPanelSampleNames().get(i))));
// Make sure every target name is the same
Assert.assertTrue(IntStream.range(0, pon.getTargetNames().size()).boxed().allMatch(i -> pon.getTargetNames().get(i).equals(ramPoN.getTargetNames().get(i))));
Assert.assertTrue(IntStream.range(0, pon.getPanelTargetNames().size()).boxed().allMatch(i -> pon.getPanelTargetNames().get(i).equals(ramPoN.getPanelTargetNames().get(i))));
}
use of org.testng.Assert in project gatk-protected by broadinstitute.
the class IntegerCopyNumberTransitionProbabilityCacheUnitTest method testBasicSoundness.
@Test
public void testBasicSoundness() {
for (final RealMatrix transitionMatrix : TRANSITION_MATRICES) {
final IntegerCopyNumberTransitionProbabilityCache cache = new IntegerCopyNumberTransitionProbabilityCache(new IntegerCopyNumberTransitionMatrix(transitionMatrix, 0));
for (final int dist : DISTANCES) {
final RealMatrix transitionMatrixExponentiated = cache.getTransitionProbabilityMatrix(dist);
/* assert positivity */
Assert.assertTrue(Arrays.stream(transitionMatrixExponentiated.getData()).flatMapToDouble(Arrays::stream).allMatch(d -> d >= 0));
/* assert conservation of probability */
for (int c = 0; c < transitionMatrix.getColumnDimension(); c++) {
Assert.assertEquals(Arrays.stream(transitionMatrixExponentiated.getColumn(c)).sum(), 1.0, EPSILON);
}
/* assert correctness, T(2*d) = T(d)*T(d) */
assertEqualMatrices(cache.getTransitionProbabilityMatrix(2 * dist), transitionMatrixExponentiated.multiply(transitionMatrixExponentiated));
}
/* assert loss of initial state over long distances, i.e. all columns must be equal */
final RealMatrix longRangeTransitionMatrix = cache.getTransitionProbabilityMatrix(Integer.MAX_VALUE);
final double[] firstColumn = longRangeTransitionMatrix.getColumn(0);
final RealMatrix syntheticLongRangeTransitionMatrix = new Array2DRowRealMatrix(firstColumn.length, firstColumn.length);
for (int i = 0; i < firstColumn.length; i++) {
syntheticLongRangeTransitionMatrix.setColumn(i, firstColumn);
}
assertEqualMatrices(longRangeTransitionMatrix, syntheticLongRangeTransitionMatrix);
final double[] stationary = cache.getStationaryProbabilityVector().toArray();
ArrayAsserts.assertArrayEquals(stationary, firstColumn, EPSILON);
}
}
use of org.testng.Assert in project gatk-protected by broadinstitute.
the class CreatePanelOfNormalsIntegrationTest method assertRamPoNDuplicate.
/**
* Assert that we can create a valid ram pon duplicate.
*
* @param pon never {@code null}
*/
private void assertRamPoNDuplicate(final PCACoveragePoN pon) {
final PCACoveragePoN ramPoN = new RamPCACoveragePoN(pon);
PoNTestUtils.assertEqualsMatrix(pon.getLogNormalizedCounts(), ramPoN.getLogNormalizedCounts(), false);
PoNTestUtils.assertEqualsMatrix(pon.getLogNormalizedPInverseCounts(), ramPoN.getLogNormalizedPInverseCounts(), false);
PoNTestUtils.assertEqualsMatrix(pon.getNormalizedCounts(), ramPoN.getNormalizedCounts(), false);
PoNTestUtils.assertEqualsMatrix(pon.getReducedPanelCounts(), ramPoN.getReducedPanelCounts(), false);
PoNTestUtils.assertEqualsMatrix(pon.getReducedPanelPInverseCounts(), ramPoN.getReducedPanelPInverseCounts(), false);
PoNTestUtils.assertEqualsDoubleArrays(pon.getTargetFactors(), ramPoN.getTargetFactors());
final List<Target> ponPanelTargets = pon.getPanelTargets();
final List<Target> ponTargets = pon.getTargets();
final List<Target> ponRawTargets = pon.getRawTargets();
final List<Target> ramPoNPanelTargets = ramPoN.getPanelTargets();
final List<Target> ramPoNTargets = ramPoN.getTargets();
final List<Target> ramPoNRawTargets = ramPoN.getRawTargets();
Assert.assertEquals(ponPanelTargets.size(), ramPoNPanelTargets.size());
Assert.assertEquals(ponTargets.size(), ramPoNTargets.size());
// Make sure every target is the same
Assert.assertTrue(IntStream.range(0, ponRawTargets.size()).boxed().allMatch(i -> ponRawTargets.get(i).equals(ramPoNRawTargets.get(i))));
Assert.assertTrue(IntStream.range(0, ponTargets.size()).boxed().allMatch(i -> ponTargets.get(i).equals(ramPoNTargets.get(i))));
Assert.assertTrue(IntStream.range(0, ponPanelTargets.size()).boxed().allMatch(i -> ponPanelTargets.get(i).equals(ramPoNPanelTargets.get(i))));
// Make sure every sample name is the same
Assert.assertTrue(IntStream.range(0, pon.getSampleNames().size()).boxed().allMatch(i -> pon.getSampleNames().get(i).equals(ramPoN.getSampleNames().get(i))));
Assert.assertTrue(IntStream.range(0, pon.getPanelSampleNames().size()).boxed().allMatch(i -> pon.getPanelSampleNames().get(i).equals(ramPoN.getPanelSampleNames().get(i))));
// Make sure every target name is the same
Assert.assertTrue(IntStream.range(0, pon.getTargetNames().size()).boxed().allMatch(i -> pon.getTargetNames().get(i).equals(ramPoN.getTargetNames().get(i))));
Assert.assertTrue(IntStream.range(0, pon.getPanelTargetNames().size()).boxed().allMatch(i -> pon.getPanelTargetNames().get(i).equals(ramPoN.getPanelTargetNames().get(i))));
}
use of org.testng.Assert in project JGroups by belaban.
the class GroupRequestTest method testCancel.
public void testCancel() throws Exception {
MyCorrelator corr = new MyCorrelator(true, null, 0);
GroupRequest<Integer> req = new GroupRequest<>(corr, Arrays.asList(a, b, c), RequestOptions.SYNC());
corr.setGroupRequest(req);
req.cancel(true);
RspList<Integer> rsps = req.execute(new Buffer(buf, 0, buf.length), true);
System.out.println("rsps:\n" + rsps);
assert rsps.size() == 3;
long num_not_received = rsps.values().stream().filter(rsp -> !rsp.wasReceived()).count();
assert num_not_received == 3;
assert req.isCancelled();
final GroupRequest<Integer> req2 = new GroupRequest<>(corr, Arrays.asList(a, b, c), RequestOptions.SYNC());
corr.setGroupRequest(req2);
new Thread(() -> {
Util.sleep(1000);
req2.cancel(true);
}).start();
rsps = req2.execute(new Buffer(buf, 0, buf.length), true);
System.out.println("rsps:\n" + rsps);
assert rsps.size() == 3;
num_not_received = rsps.values().stream().filter(rsp -> !rsp.wasReceived()).count();
assert num_not_received == 3;
assert req2.isCancelled();
}
use of org.testng.Assert in project JGroups by belaban.
the class ExecutingServiceTest2 method testDisconnect.
@Test
public void testDisconnect() throws Exception {
JChannel channel1 = new JChannel(Util.getTestStack(new CENTRAL_EXECUTOR()));
JChannel channel2 = new JChannel(Util.getTestStack(new CENTRAL_EXECUTOR()));
channels.add(channel1);
channels.add(channel2);
channel1.connect("test-cluster");
channel2.connect("test-cluster");
Util.waitUntilAllChannelsHaveSameView(20000, 1000, channel1, channel2);
final ExecutionService executionService = new ExecutionService(channel1);
ExecutionRunner executionRunner1 = new ExecutionRunner(channel1);
ExecutionRunner executionRunner2 = new ExecutionRunner(channel2);
Thread runner1 = new Thread(executionRunner1);
threads.add(runner1);
runner1.start();
Thread runner2 = new Thread(executionRunner2);
threads.add(runner2);
runner2.start();
final AtomicInteger submittedTasks = new AtomicInteger();
final AtomicInteger finishedTasks = new AtomicInteger();
final FutureListener<Void> listener = future -> {
finishedTasks.incrementAndGet();
synchronized (ExecutingServiceTest2.this) {
ExecutingServiceTest2.this.notify();
}
};
Thread submitter = new Thread(new Runnable() {
@Override
public void run() {
// Two long running tasks that should be sent to each runner
submit(true);
submit(true);
while (!Thread.interrupted()) {
submit(false);
// Throttle
try {
Thread.sleep(50);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
private void submit(boolean wait) {
Callable<Void> task = new Wait(wait);
NotifyingFuture<Void> future = executionService.submit(task);
submittedTasks.incrementAndGet();
future.setListener(listener);
}
});
threads.add(submitter);
submitter.start();
// Run for 2 seconds
Thread.sleep(500);
// Close channel
channel2.close();
// Stop submitting
submitter.interrupt();
submitter.join();
// Wait for running tasks to finish
synchronized (this) {
int lastFinished = finishedTasks.get();
while (submittedTasks.get() > finishedTasks.get()) {
wait(10000);
if (lastFinished == finishedTasks.get()) {
assert false : "Tasks still outstanding, none finished in the last 10s";
}
lastFinished = finishedTasks.get();
}
}
Assert.assertEquals(submittedTasks.get(), finishedTasks.get(), "Tasks not finished");
}
Aggregations