Created
April 30, 2022 17:10
-
-
Save Arham4/37f103e2139823b690e799544309a507 to your computer and use it in GitHub Desktop.
2022 Spring IEEE International Contest on Software Testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.mooctest; | |
import org.junit.Test; | |
import static org.junit.Assert.*; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class HeapElementTest { | |
@Test(timeout = 4000) | |
public void test() throws Throwable { | |
HeapElement heapElement0 = new HeapElement(-999.42542, new Object()); | |
HeapElement heapElement1 = new HeapElement(2347, heapElement0); | |
assertNotEquals(heapElement0, heapElement1); | |
assertNotNull(heapElement1.getInfo()); | |
assertNotNull(heapElement1.toString()); | |
HeapElement heapElement2 = new HeapElement(new Integer(2347), heapElement1); | |
assertNotEquals(heapElement1, heapElement2); | |
assertEquals(heapElement2.getKey(), heapElement1.getKey(), 0); | |
HeapElement heapElement3 = new HeapElement(new Double(-999.42542), heapElement1); | |
assertNotEquals(heapElement0, heapElement3); | |
HeapElement forCoverage1 = new HeapElement(new Double(-1337)); | |
HeapElement forCoverage2 = new HeapElement(new Integer(-1337)); | |
HeapElement forCoverage3 = new HeapElement(1337); | |
HeapElement forCoverage4 = new HeapElement(-1338.0, forCoverage1); | |
} | |
@Test(timeout = 4000) | |
public void genericHeapTests() throws Throwable { | |
int firstElement = 1; | |
int secondElement = 2; | |
GenericHeap<Integer> heap = new GenericHeap<>(); | |
assertTrue(heap.isEmpty()); | |
heap.add(firstElement); | |
heap.add(secondElement); | |
assertFalse(heap.isEmpty()); | |
List<Integer> currentList = new ArrayList<>(); | |
currentList.add(secondElement); | |
currentList.add(firstElement); | |
assertEquals(currentList, heap.data); | |
assertEquals(secondElement, (int) heap.get()); | |
heap.updatePriority(firstElement); | |
heap.updatePriority(secondElement); | |
heap.updatePriority(secondElement); | |
heap.display(); // for coverage | |
assertEquals(secondElement, (int) heap.remove()); | |
assertEquals(firstElement, (int) heap.remove()); | |
assertTrue(heap.isEmpty()); | |
} | |
@Test(timeout = 4000) | |
public void biggerGenericHeapTests() throws Throwable { | |
int firstElement = 1; | |
int secondElement = 2; | |
GenericHeap<Integer> heap = new GenericHeap<>(); | |
assertTrue(heap.isEmpty()); | |
heap.add(firstElement); | |
heap.add(secondElement); | |
assertFalse(heap.isEmpty()); | |
List<Integer> currentList = new ArrayList<>(); | |
currentList.add(secondElement); | |
currentList.add(firstElement); | |
assertEquals(currentList, heap.data); | |
assertEquals(secondElement, (int) heap.get()); | |
heap.updatePriority(firstElement); | |
heap.updatePriority(secondElement); | |
heap.updatePriority(secondElement); | |
heap.display(); // for coverage | |
assertEquals(secondElement, (int) heap.remove()); | |
assertEquals(firstElement, (int) heap.remove()); | |
assertTrue(heap.isEmpty()); | |
} | |
@Test(timeout = 4000) | |
public void maxHeapTests() throws Throwable { | |
List<HeapElement> elements = new ArrayList<>(); | |
MaxHeap emptyHeap = new MaxHeap(elements); | |
HeapElement firstElement = new HeapElement(-999.42542, new Object()); | |
HeapElement secondElement = new HeapElement(2347, new Object()); | |
HeapElement thirdElement = new HeapElement(-1337, new Object()); | |
elements.add(null); | |
elements.add(firstElement); | |
elements.add(secondElement); | |
try { | |
MaxHeap heap = new MaxHeap(elements); | |
} catch (Exception ignored) { } | |
try { | |
emptyHeap.insertElement(firstElement); | |
} catch (Exception ignored) { } | |
try { | |
emptyHeap.insertElement(secondElement); | |
} catch (Exception ignored) { } | |
emptyHeap.insertElement(new HeapElement(1337, new Object())); | |
emptyHeap.insertElement(thirdElement); | |
emptyHeap.insertElement(thirdElement); | |
emptyHeap.insertElement(new HeapElement(-312123)); | |
emptyHeap.insertElement(new HeapElement(-312123)); | |
emptyHeap.insertElement(new HeapElement(-789234)); | |
emptyHeap.insertElement(new HeapElement(0)); | |
assertEquals(secondElement, emptyHeap.getElement(1)); | |
try { | |
emptyHeap.deleteElement(1); | |
} catch (Exception ignored) { } | |
try { | |
assertEquals(secondElement, emptyHeap.getElement()); | |
} catch (Exception ignored) { } | |
} | |
@Test(timeout = 4000, expected = Exception.class) | |
public void maxHeapEmptyTests() throws Throwable { | |
List<HeapElement> elements = new ArrayList<>(); | |
MaxHeap emptyHeap = new MaxHeap(elements); | |
emptyHeap.deleteElement(0); | |
} | |
@Test(timeout = 4000) | |
public void minHeapTests() throws Throwable { | |
List<HeapElement> elements = new ArrayList<>(); | |
MinHeap emptyHeap = new MinHeap(elements); | |
HeapElement firstElement = new HeapElement(-999.42542, new Object()); | |
HeapElement secondElement = new HeapElement(2347, new Object()); | |
HeapElement thirdElement = new HeapElement(1337, new Object()); | |
elements.add(null); | |
elements.add(firstElement); | |
elements.add(secondElement); | |
try { | |
MaxHeap heap = new MaxHeap(elements); | |
} catch (Exception ignored) { } | |
try { | |
emptyHeap.insertElement(firstElement); | |
} catch (Exception ignored) { } | |
try { | |
emptyHeap.insertElement(secondElement); | |
} catch (Exception ignored) { } | |
emptyHeap.insertElement(new HeapElement(1337, new Object())); | |
emptyHeap.insertElement(thirdElement); | |
emptyHeap.insertElement(thirdElement); | |
emptyHeap.insertElement(new HeapElement(312123)); | |
emptyHeap.insertElement(new HeapElement(312123)); | |
emptyHeap.insertElement(new HeapElement(789234)); | |
emptyHeap.insertElement(new HeapElement(0)); | |
assertEquals(firstElement, emptyHeap.getElement(1)); | |
try { | |
emptyHeap.deleteElement(1); | |
} catch (Exception ignored) { } | |
try { | |
assertEquals(secondElement, emptyHeap.getElement()); | |
} catch (Exception ignored) { } | |
} | |
@Test(timeout = 4000, expected = Exception.class) | |
public void minHeapEmptyTests() throws Throwable { | |
List<HeapElement> elements = new ArrayList<>(); | |
MinHeap emptyHeap = new MinHeap(elements); | |
emptyHeap.deleteElement(0); | |
} | |
@Test(timeout = 4000) | |
public void minPriorityQueueTests() throws Throwable { | |
int firstElement = 5; | |
MinPriorityQueue oneQueue = new MinPriorityQueue(1); | |
assertTrue(oneQueue.isEmpty()); | |
oneQueue.insert(firstElement); | |
assertTrue(oneQueue.isFull()); | |
assertEquals(firstElement, oneQueue.peek()); | |
oneQueue.print(); // for coverage | |
oneQueue.heapSort(); | |
oneQueue.delete(); | |
assertTrue(oneQueue.isEmpty()); | |
} | |
@Test(timeout = 4000) | |
public void biggerMinPriorityQueueTests() throws Throwable { | |
MinPriorityQueue bigQueue = new MinPriorityQueue(5); | |
assertTrue(bigQueue.isEmpty()); | |
assertFalse(bigQueue.isFull()); | |
bigQueue.insert(Integer.MIN_VALUE); | |
bigQueue.insert(-10); | |
bigQueue.insert(-5); | |
bigQueue.insert(-13); | |
bigQueue.insert(-7); | |
bigQueue.insert(-100); // branch coverage | |
assertEquals(Integer.MIN_VALUE, bigQueue.peek()); | |
bigQueue.print(); // for coverage | |
assertEquals(Integer.MIN_VALUE, bigQueue.delete()); | |
assertEquals(-13, bigQueue.delete()); | |
assertEquals(-10, bigQueue.delete()); | |
assertEquals(-7, bigQueue.delete()); | |
assertEquals(-5, bigQueue.delete()); | |
assertTrue(bigQueue.isEmpty()); | |
assertFalse(bigQueue.isFull()); | |
} | |
@Test(timeout = 4000) | |
public void heapSort() throws Throwable { | |
MinPriorityQueue bigQueue = new MinPriorityQueue(5); | |
assertTrue(bigQueue.isEmpty()); | |
assertFalse(bigQueue.isFull()); | |
bigQueue.insert(Integer.MIN_VALUE); | |
bigQueue.insert(-10); | |
bigQueue.insert(-5); | |
bigQueue.insert(-13); | |
bigQueue.insert(-7); | |
bigQueue.insert(-100); // branch coverage | |
assertEquals(Integer.MIN_VALUE, bigQueue.peek()); | |
bigQueue.print(); // for coverage | |
bigQueue.heapSort(); | |
assertEquals(-5, bigQueue.delete()); | |
assertTrue(bigQueue.isEmpty()); | |
assertFalse(bigQueue.isFull()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.mooctest; | |
import net.mooctest.delegates.Action1; | |
import net.mooctest.triggers.*; | |
import org.junit.Test; | |
import static org.junit.Assert.*; | |
public class StateMachineConfigTest { | |
@Test(timeout = 4000) | |
public void test() throws Throwable { | |
StateMachineConfig<Object, String> stateMachineConfig0 = new StateMachineConfig<Object, String>(); | |
Object object0 = new Object(); | |
StateMachine<Object, String> machine = new StateMachine<>(object0, stateMachineConfig0); | |
StateConfiguration<Object, String> stateConfiguration0 = machine.configure(object0); | |
StateConfiguration<Object, String> stateConfiguration1 = machine.configure(object0); | |
assertNotEquals(stateConfiguration1, stateConfiguration0); | |
} | |
@Test(timeout = 4000) | |
public void testTrigger() throws Throwable { | |
StateMachineConfig<Object, String> stateMachineConfig0 = new StateMachineConfig<Object, String>(); | |
Object object0 = new Object(); | |
String trigger = "test0"; | |
StateMachine<Object, String> machine = new StateMachine<>(object0, stateMachineConfig0); | |
StateConfiguration<Object, String> stateConfiguration0 = machine.configure(object0); | |
StateConfiguration<Object, String> stateConfiguration1 = machine.configure(object0); | |
assertNotEquals(stateConfiguration1, stateConfiguration0); | |
assertFalse(stateMachineConfig0.isTriggerConfigured(trigger)); | |
final int[] number = {0}; | |
StateRepresentation<Object, String> representation = stateMachineConfig0.getRepresentation(object0); | |
representation.addTriggerBehaviour(new DynamicTriggerBehaviour<>("test0", arg1 -> null, () -> true, arg1 -> number[0]++)); | |
stateMachineConfig0.setTriggerParameters("test0", object0.getClass()); | |
stateConfiguration0.onEntryFrom("test0", () -> { | |
number[0]++; | |
}); | |
machine.publicFire("test0", object0.getClass()); | |
assertEquals(1, number[0]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment