package urban.shapes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import static org.junit.Assert.*;
import urban.model.Agent;
import urban.model.Rule;
import urban.model.Site;
import static urban.util.Pair.pairOf;
public class RateCalculatorTest {
private static final Shape S1 = new Shape(A_f("0"));
private static Set<Agent> A_f(String string) {
return Collections.singleton(new Agent("A",Collections.singleton(new Site("A","f",string,null))));
}
private static final Generator G = gen("A(f~0)<->A(f~1)");
@Test
public void testCalculateRates(){
ShapeParameters p = new ShapeParameters();
p.constants.put(G,3.16227766016838);
p.epsilons.put(S1, Math.log(0.1));
p.lambda.put(pairOf(G,S1), -0.5);
Rule r = new Rule(null,A_f("0"), A_f("1"), true, 0.0, 0.0);
Rule expected = new Rule(null,A_f("0"), A_f("1"), true, 1.0, 10.0);
Rule actual = new RateCalculator(p).calculateRates(G, r);
assertEquals(""+expected, ""+actual);
}
@SuppressWarnings("unchecked")
@Test
public void testCalculateRates_EmptyParameters(){
Collection<Agent> f0 = join(A_f("0"));
Collection<Agent> f1 = join(A_f("1"));
ShapeParameters p = new ShapeParameters();
Rule r = new Rule(null,f0, f1, true, 0.0, 0.0);
Rule expected = new Rule(null,f0, f1, true, 0.0, 0.0);
Rule actual = new RateCalculator(p).calculateRates(G, r);
assertEquals(""+expected, ""+actual);
}
private Collection<Agent> join(Collection<Agent>... as) {
List<Agent> l = new ArrayList<Agent>();
for (Collection<Agent> a : as)
l.addAll(a);
return l;
}
private static Generator gen(String text){
return Generator.createGeneratorFromString(text);
}
}