1 package org.simantics.scl.runtime.tests;
3 import java.util.Random;
5 import org.junit.Assert;
7 import org.simantics.scl.runtime.chr.Fact;
8 import org.simantics.scl.runtime.chr.FactActivationQueue;
10 import gnu.trove.list.array.TIntArrayList;
12 public class TestFactActivationQueue {
13 public static Random RANDOM = new Random();
15 private static class MyFact implements Fact {
19 public MyFact(TIntArrayList list, int priority) {
21 this.priority = priority;
25 public int activate(Object context, int priority) {
26 Assert.assertEquals(this.priority, priority);
32 public boolean isAlive() {
37 private void testRandomly(int priorities, int size) {
38 FactActivationQueue queue = new FactActivationQueue(priorities);
39 TIntArrayList list = new TIntArrayList(size);
40 for(int i=0;i<size;++i) {
41 int val = RANDOM.nextInt(priorities);
42 queue.add(val, new MyFact(list, val));
44 queue.activate(null, priorities);
45 Assert.assertEquals(size, list.size());
46 for(int i=1;i<list.size();++i) {
47 int a = list.get(i-1);
49 Assert.assertTrue(a <= b);
54 public void testRandomly() {
55 for(int i=0;i<10000;++i)
56 testRandomly(10, 10000);