List of usage examples for org.apache.commons.math.stat Frequency getPct
public double getPct(char v)
From source file:com.sse.abtester.VariationAssignerTest.java
/** * Test n variants./*from w w w. j a v a2 s .c o m*/ * * @param num_variants the num_variants */ public void testNVariants(int num_variants) { // make up some variants AbstractMap<String, IVariant<VariantBean>> coll = new HashMap<String, IVariant<VariantBean>>(); for (int i = 0; i < num_variants; i++) { String name = "Bean_" + i; IVariant<VariantBean> vb = new VariantBean(name); vb.setDispatchable(true); // else non of the bean is // copied into normalized/weighted collections vb.setTargetFreq(1.0 / num_variants); vb.setVariationStrategy(new Default()); coll.put(name, vb); } VariationAssigner<VariantBean> va = new VariationAssigner<VariantBean>(); va.setIVariantCollection(coll); Frequency f = new Frequency(); MockHttpServletRequest req = new MockHttpServletRequest(); int TEST_LOOPS = 1000; double ALLOWABLE_DELTA = 100.0 / TEST_LOOPS; // rough check for (int i = 0; i < TEST_LOOPS; i++) { IVariant<VariantBean> assigned = va.enrollRequest(req); if (assigned != null) f.addValue(assigned.getName()); } for (IVariant<VariantBean> vrb : coll.values()) { assertEquals(1.0 / num_variants, f.getPct(vrb.getName()), // NaN here can mean unknown name ALLOWABLE_DELTA); } }