This repository has been archived on 2025-01-16. You can view files and clone it, but cannot push or open issues or pull requests.
AuD-2021-Exam-Prep/test/aud/exam/prep/tree/OrderedTreeProcessorTest.java

55 lines
1.4 KiB
Java
Raw Normal View History

package aud.exam.prep.tree;
import aud.exam.prep.ListProvider;
import aud.exam.prep.tree.OrderedTreeProcessor;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ArgumentsSource;
import java.util.List;
import static aud.exam.prep.Tests.CMP;
import static org.junit.jupiter.api.Assertions.*;
public abstract class OrderedTreeProcessorTest<T> {
protected final OrderedTreeProcessor<Integer, T> processor;
protected OrderedTreeProcessorTest(OrderedTreeProcessor<Integer, T> processor) {
this.processor = processor;
}
@Test
void testThat_newEmptyTreeWorks() {
T t = processor.newEmptyTree();
assertTrue(processor.check(t, CMP));
assertEquals(-1, processor.height(t));
assertTrue(processor.isBalanced(t));
assertEquals(0, processor.numberOfNodes(t));
for (int i = 0; i < 10; i++) {
assertEquals(0, processor.numberOfNodesOnLevel(t, i));
}
assertIterableEquals(List.of(), processor.iterate(t));
}
@ParameterizedTest
@ArgumentsSource(ListProvider.class)
void testThat_insertAndIterateWork(List<Integer> list) {
T t = processor.newEmptyTree();
for (var n : list) {
t = processor.insert(t, n, CMP);
}
list.sort(CMP);
assertTrue(processor.check(t, CMP));
assertIterableEquals(list, processor.iterate(t));
}
}