http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/TestProduct.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/TestProduct.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/TestProduct.java deleted file mode 100644 index f1e835a..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/TestProduct.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.datamodels; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import java.util.Map; - -import org.apache.bigtop.bigpetstore.datagenerator.Constants; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; -import org.junit.Test; - -import com.google.common.collect.Maps; - -public class TestProduct -{ - - @Test - public void testString() - { - Map<String, Object> fields = Maps.newHashMap(); - fields.put(Constants.PRODUCT_CATEGORY, "poop bags"); - fields.put(Constants.PRODUCT_QUANTITY, 120); - fields.put("price", 12.80); - - Product product = new Product(fields); - - assertEquals(product.getFieldValueAsString(Constants.PRODUCT_CATEGORY), "poop bags"); - assertEquals(product.getFieldValueAsString("price"), "12.8"); - assertEquals(product.getFieldValueAsString(Constants.PRODUCT_QUANTITY), "120"); - } - - @Test - public void testDouble() - { - Map<String, Object> fields = Maps.newHashMap(); - fields.put(Constants.PRODUCT_CATEGORY, "poop bags"); - fields.put(Constants.PRODUCT_QUANTITY, 120); - fields.put("price", 12.80); - - Product product = new Product(fields); - - assertNull(product.getFieldValueAsDouble(Constants.PRODUCT_CATEGORY)); - assertEquals(product.getFieldValueAsDouble("price"), 12.80, 1e-5); - assertNull(product.getFieldValueAsDouble(Constants.PRODUCT_QUANTITY)); - } - - @Test - public void testLong() - { - Map<String, Object> fields = Maps.newHashMap(); - fields.put(Constants.PRODUCT_CATEGORY, "poop bags"); - fields.put(Constants.PRODUCT_QUANTITY, 120); - fields.put("price", 12.80); - - Product product = new Product(fields); - - assertNull(product.getFieldValueAsLong(Constants.PRODUCT_CATEGORY)); - assertNull(product.getFieldValueAsLong("price")); - assertEquals((long) product.getFieldValueAsLong(Constants.PRODUCT_QUANTITY), 120L); - } - -}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/TestMarkovModelBuilder.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/TestMarkovModelBuilder.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/TestMarkovModelBuilder.java deleted file mode 100644 index b9e63f2..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/TestMarkovModelBuilder.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels; - -import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovModel; -import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovModelBuilder; -import org.junit.Test; - -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.matchers.JUnitMatchers.*; - -public class TestMarkovModelBuilder -{ - - @Test - public void testAddStateState() - { - MarkovModelBuilder<String> builder = MarkovModelBuilder.create(); - - builder.addStartState("a", 1.0); - - MarkovModel<String> msm = builder.build(); - - assertThat(msm.getStartWeights().keySet(), hasItem("a")); - assertEquals((double) msm.getStartWeights().get("a"), (double) 1.0, 0.000001); - - } - - @Test - public void testAddEdgeTransition() - { - MarkovModelBuilder<String> builder = MarkovModelBuilder.create(); - - builder.addTransition("a", "b", 1.0); - - MarkovModel<String> msm = builder.build(); - - assertThat(msm.getTransitionWeights().keySet(), hasItem("a")); - assertThat(msm.getTransitionWeights().get("a").keySet(), hasItem("b")); - assertEquals((double) msm.getTransitionWeights().get("a").get("b"), (double) 1.0, 0.000001); - } - - @Test - public void testBuildMSM() - { - MarkovModelBuilder<String> builder = MarkovModelBuilder.create(); - - builder.addStartState("a", 1.0); - builder.addTransition("a", "b", 1.0); - builder.addTransition("a", "c", 1.0); - - MarkovModel<String> msm = builder.build(); - - assertThat(msm.getStartWeights().keySet(), hasItem("a")); - assertThat(msm.getTransitionWeights().keySet(), hasItem("a")); - assertThat(msm.getTransitionWeights().get("a").keySet(), hasItem("b")); - assertThat(msm.getTransitionWeights().get("a").keySet(), hasItem("c")); - assertEquals((double) msm.getTransitionWeights().get("a").get("b"), (double) 1.0, 0.000001); - assertEquals((double) msm.getTransitionWeights().get("a").get("c"), (double) 1.0, 0.000001); - } - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/TestMarkovProcess.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/TestMarkovProcess.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/TestMarkovProcess.java deleted file mode 100644 index e2ff4d5..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/TestMarkovProcess.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.matchers.JUnitMatchers.hasItem; - -import java.util.Arrays; - -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; -import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovModel; -import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovModelBuilder; -import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovProcess; -import org.junit.Test; - -public class TestMarkovProcess -{ - - @Test - public void test() throws Exception - { - SeedFactory factory = new SeedFactory(1245); - MarkovModelBuilder<String> builder = MarkovModelBuilder.create(); - - builder.addStartState("a", 1.0); - builder.addTransition("a", "b", 1.0); - builder.addTransition("a", "c", 1.0); - - MarkovModel<String> msm = builder.build(); - MarkovProcess<String> process = MarkovProcess.create(msm, factory); - - String firstState = process.sample(); - assertEquals(firstState, "a"); - - String secondState = process.sample(); - assertThat(Arrays.asList("b", "c"), hasItem(secondState)); - } - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/TestMultinomialPDF.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/TestMultinomialPDF.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/TestMultinomialPDF.java deleted file mode 100644 index 8952389..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/TestMultinomialPDF.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs; - -import java.util.Map; -import java.util.Set; - -import org.junit.Assert; -import org.junit.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Sets; - -public class TestMultinomialPDF -{ - - @Test - public void testToString() - { - Map<String, Double> objects = ImmutableMap.of("A", 0.1, "B", 0.3, "C", 0.5); - MultinomialPDF<String> pdf = new MultinomialPDF<String>(objects); - String string = pdf.toString(); - Set<String> observed = Sets.newHashSet(string.split("\n")); - Set<String> expected = Sets.newHashSet("0.1,A", "0.3,B", "0.5,C"); - - Assert.assertEquals(expected, observed); - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestBoundedMultiModalGaussianSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestBoundedMultiModalGaussianSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestBoundedMultiModalGaussianSampler.java deleted file mode 100644 index 9300d08..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestBoundedMultiModalGaussianSampler.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers; - -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; -import org.apache.commons.lang3.tuple.Pair; -import org.junit.Test; - -import com.google.common.collect.Lists; - -public class TestBoundedMultiModalGaussianSampler -{ - - @Test - public void testSample() throws Exception - { - double upperbound = 10.0; - double lowerbound = 1.0; - - List<Pair<Double, Double>> distributions = Lists.newArrayList(Pair.of(2.0, 2.0), Pair.of(7.5, 2.0)); - - SeedFactory seedFactory = new SeedFactory(1234); - - Sampler<Double> sampler = new BoundedMultiModalGaussianSampler(distributions, lowerbound, upperbound, seedFactory); - - Double result = sampler.sample(); - - assertTrue(result >= lowerbound); - assertTrue(result <= upperbound); - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestExponentialSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestExponentialSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestExponentialSampler.java deleted file mode 100644 index 228b97d..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestExponentialSampler.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers; - -import static org.junit.Assert.assertTrue; - -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.ExponentialSampler; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; -import org.junit.Test; - -public class TestExponentialSampler -{ - - @Test - public void testSample() throws Exception - { - double lambda = 1.0 / 2.0; - - SeedFactory seedFactory = new SeedFactory(1234); - - Sampler<Double> sampler = new ExponentialSampler(lambda, seedFactory); - - Double result = sampler.sample(); - - assertTrue(result >= 0.0); - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestGaussianSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestGaussianSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestGaussianSampler.java deleted file mode 100644 index fbe8c18..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestGaussianSampler.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers; - -import static org.junit.Assert.assertTrue; - -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.GaussianSampler; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; -import org.junit.Test; - -public class TestGaussianSampler -{ - - @Test - public void testSample() throws Exception - { - double mean = 2.0; - double var = 1.0; - - SeedFactory seedFactory = new SeedFactory(1234); - - Sampler<Double> sampler = new GaussianSampler(mean, var, seedFactory); - - Double result = sampler.sample(); - - assertTrue(result >= -10); - assertTrue(result <= 10); - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestRouletteWheelSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestRouletteWheelSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestRouletteWheelSampler.java deleted file mode 100644 index f1152c5..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestRouletteWheelSampler.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers; - -import static org.junit.Assert.assertThat; -import static org.junit.matchers.JUnitMatchers.hasItem; - -import java.util.Map; - -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.RouletteWheelSampler; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; -import org.junit.Test; - -import com.google.common.collect.ImmutableMap; - -public class TestRouletteWheelSampler -{ - - @Test - public void testSample() throws Exception - { - Map<String, Double> dataPoints = ImmutableMap.of( - "a", 0.25, - "b", 0.25, - "c", 0.25, - "d", 0.25 - ); - - SeedFactory seedFactory = new SeedFactory(1234); - - Sampler<String> sampler = new RouletteWheelSampler<String>(dataPoints, seedFactory); - - String result = sampler.sample(); - - assertThat(dataPoints.keySet(), hasItem(result)); - } - - @Test - public void testSampleUnnormalized() throws Exception - { - Map<String, Double> dataPoints = ImmutableMap.of( - "a", 1.0, - "b", 1.0, - "c", 1.0, - "d", 1.0 - ); - - SeedFactory seedFactory = new SeedFactory(1234); - - Sampler<String> sampler = new RouletteWheelSampler<String>(dataPoints, seedFactory); - - String result = sampler.sample(); - - assertThat(dataPoints.keySet(), hasItem(result)); - } - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestSequenceSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestSequenceSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestSequenceSampler.java deleted file mode 100644 index 6684773..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestSequenceSampler.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers; - -import static org.junit.Assert.assertEquals; - -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.SequenceSampler; -import org.junit.Test; - -public class TestSequenceSampler -{ - - @Test - public void testSample() throws Exception - { - Sampler<Integer> sampler = new SequenceSampler(0, 10, 1); - - for(int i = 0; i < 10; i++) - { - Integer value = sampler.sample(); - assertEquals( (int) value, i); - } - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestUniformIntSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestUniformIntSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestUniformIntSampler.java deleted file mode 100644 index a700cdf..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/TestUniformIntSampler.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers; - -import static org.junit.Assert.assertTrue; - -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.UniformIntSampler; -import org.junit.Test; - -public class TestUniformIntSampler -{ - - @Test - public void testSample() throws Exception - { - int upperbound = 10; - int lowerbound = 1; - - SeedFactory seedFactory = new SeedFactory(1234); - - Sampler<Integer> sampler = new UniformIntSampler(lowerbound, upperbound, seedFactory); - - Integer result = sampler.sample(); - - assertTrue(result >= lowerbound); - assertTrue(result <= upperbound); - } - - @Test - public void testSampleInclusive() throws Exception - { - int upperbound = 2; - int lowerbound = 1; - - SeedFactory seedFactory = new SeedFactory(1234); - - Sampler<Integer> sampler = new UniformIntSampler(lowerbound, upperbound, seedFactory); - - Integer result = sampler.sample(); - - assertTrue(result >= lowerbound); - assertTrue(result <= upperbound); - } - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerLocationPDF.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerLocationPDF.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerLocationPDF.java deleted file mode 100644 index 0800c58..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerLocationPDF.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.customer; - -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.bigtop.bigpetstore.datagenerator.Constants; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Store; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord; -import org.apache.commons.lang3.tuple.Pair; -import org.junit.Test; - -public class TestCustomerLocationPDF -{ - - @Test - public void testProbability() throws Exception - { - List<ZipcodeRecord> zipcodes = Arrays.asList(new ZipcodeRecord[] { - new ZipcodeRecord("11111", Pair.of(1.0, 1.0), "AZ", "Tempte", 30000.0, 100), - new ZipcodeRecord("22222", Pair.of(2.0, 2.0), "AZ", "Phoenix", 45000.0, 200), - new ZipcodeRecord("33333", Pair.of(3.0, 3.0), "AZ", "Flagstaff", 60000.0, 300) - }); - - List<Store> stores = new ArrayList<Store>(); - for(int i = 0; i < zipcodes.size(); i++) - { - Store store = new Store(i, "Store_" + i, zipcodes.get(i)); - stores.add(store); - } - - CustomerLocationPDF customerLocationPDF = new CustomerLocationPDF(zipcodes, stores.get(0), - Constants.AVERAGE_CUSTOMER_STORE_DISTANCE); - - double prob = customerLocationPDF.probability(zipcodes.get(0)); - - assertTrue(prob > 0.0); - } - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerSampler.java deleted file mode 100644 index 639b2af..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerSampler.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.customer; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import org.apache.bigtop.bigpetstore.datagenerator.Constants; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Customer; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Store; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord; -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; -import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.ProbabilityDensityFunction; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.ConditionalSampler; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.RouletteWheelSampler; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.SequenceSampler; -import org.apache.commons.lang3.tuple.Pair; -import org.junit.Test; - -import com.google.common.collect.Maps; - -public class TestCustomerSampler -{ - protected ConditionalSampler<ZipcodeRecord, Store> buildLocationSampler(List<Store> stores, List<ZipcodeRecord> records, - SeedFactory factory) - { - final Map<Store, Sampler<ZipcodeRecord>> locationSamplers = Maps.newHashMap(); - for(Store store : stores) - { - ProbabilityDensityFunction<ZipcodeRecord> locationPDF = new CustomerLocationPDF(records, - store, Constants.AVERAGE_CUSTOMER_STORE_DISTANCE); - Sampler<ZipcodeRecord> locationSampler = RouletteWheelSampler.create(records, locationPDF, factory); - locationSamplers.put(store, locationSampler); - } - - return new ConditionalSampler<ZipcodeRecord, Store>() - { - public ZipcodeRecord sample(Store store) throws Exception - { - return locationSamplers.get(store).sample(); - } - }; - } - - @Test - public void testBuild() throws Exception - { - SeedFactory factory = new SeedFactory(1234); - - Collection<String> nameList = Arrays.asList(new String[] {"Fred", "Gary", "George", "Fiona"}); - List<ZipcodeRecord> zipcodes = Arrays.asList(new ZipcodeRecord[] { - new ZipcodeRecord("11111", Pair.of(1.0, 1.0), "AZ", "Tempte", 30000.0, 100), - new ZipcodeRecord("22222", Pair.of(2.0, 2.0), "AZ", "Phoenix", 45000.0, 200), - new ZipcodeRecord("33333", Pair.of(3.0, 3.0), "AZ", "Flagstaff", 60000.0, 300) - }); - - List<Store> stores = new ArrayList<Store>(); - for(int i = 0; i < zipcodes.size(); i++) - { - Store store = new Store(i, "Store_" + i, zipcodes.get(i)); - stores.add(store); - } - - - Sampler<Integer> idSampler = new SequenceSampler(); - Sampler<String> nameSampler = RouletteWheelSampler.createUniform(nameList, factory); - Sampler<Store> storeSampler = RouletteWheelSampler.createUniform(stores, factory); - ConditionalSampler<ZipcodeRecord, Store> zipcodeSampler = buildLocationSampler(stores, zipcodes, factory); - - Sampler<Customer> sampler = new CustomerSampler(idSampler, nameSampler, nameSampler, storeSampler, zipcodeSampler); - - Customer customer = sampler.sample(); - - assertNotNull(customer); - assertTrue(customer.getId() >= 0); - assertNotNull(customer.getName()); - assertNotNull(customer.getName().getLeft()); - assertTrue(nameList.contains(customer.getName().getLeft())); - assertNotNull(customer.getName().getRight()); - assertTrue(nameList.contains(customer.getName().getRight())); - assertNotNull(customer.getLocation()); - assertTrue(zipcodes.contains(customer.getLocation())); - - } - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerSamplerBuilder.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerSamplerBuilder.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerSamplerBuilder.java deleted file mode 100644 index 74c8348..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerSamplerBuilder.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.customer; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Customer; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Store; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.InputData; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.Names; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord; -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; -import org.apache.commons.lang3.tuple.Pair; -import org.junit.Test; - -import com.google.common.collect.ImmutableMap; - -public class TestCustomerSamplerBuilder -{ - - @Test - public void testSample() throws Exception - { - Map<String, Double> nameList = ImmutableMap.of("Fred", 1.0, "George", 1.0, "Gary", 1.0, "Fiona", 1.0); - List<ZipcodeRecord> zipcodes = Arrays.asList(new ZipcodeRecord[] { - new ZipcodeRecord("11111", Pair.of(1.0, 1.0), "AZ", "Tempte", 30000.0, 100), - new ZipcodeRecord("22222", Pair.of(2.0, 2.0), "AZ", "Phoenix", 45000.0, 200), - new ZipcodeRecord("33333", Pair.of(3.0, 3.0), "AZ", "Flagstaff", 60000.0, 300) - }); - - Names names = new Names(nameList, nameList); - - // don't need product categories for building customers - InputData inputData = new InputData(zipcodes, names); - - List<Store> stores = Arrays.asList(new Store(0, "Store_0", zipcodes.get(0)), - new Store(1, "Store_1", zipcodes.get(1)), - new Store(2, "Store_2", zipcodes.get(2)) - ); - - SeedFactory factory = new SeedFactory(1234); - - CustomerSamplerBuilder builder = new CustomerSamplerBuilder(stores, inputData, factory); - Sampler<Customer> sampler = builder.build(); - - Customer customer = sampler.sample(); - - assertNotNull(customer); - assertTrue(customer.getId() >= 0); - assertNotNull(customer.getName()); - assertNotNull(customer.getName().getLeft()); - assertNotNull(customer.getName().getRight()); - assertNotNull(customer.getLocation()); - - } - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductBase.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductBase.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductBase.java deleted file mode 100644 index 3b7c2e8..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductBase.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.products.cartesian; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.Map; - -import org.junit.Assert; -import org.junit.Test; - -public class TestCartesianProductBase -{ - @Test - public void testNext() - { - Iterator<Map<String, Double>> iter = new CartesianProductBase<Double>("count", - Arrays.asList(1.0, 2.0, 3.0)); - - Assert.assertTrue(iter.hasNext()); - - Map<String, Double> map = iter.next(); - Assert.assertEquals(1, map.size()); - Assert.assertTrue(map.containsKey("count")); - Assert.assertEquals( (double) map.get("count"), (double) 1.0, 0.0001); - - Assert.assertTrue(iter.hasNext()); - - map = iter.next(); - Assert.assertEquals(1, map.size()); - Assert.assertTrue(map.containsKey("count")); - Assert.assertEquals( (double) map.get("count"), (double) 2.0, 0.0001); - - Assert.assertTrue(iter.hasNext()); - - map = iter.next(); - Assert.assertEquals(1, map.size()); - Assert.assertTrue(map.containsKey("count")); - Assert.assertEquals( (double) map.get("count"), (double) 3.0, 0.0001); - - Assert.assertFalse(iter.hasNext()); - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductField.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductField.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductField.java deleted file mode 100644 index 5071a54..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductField.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.products.cartesian; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.Map; - -import org.junit.Assert; -import org.junit.Test; - -public class TestCartesianProductField -{ - - @Test - public void testTwoLevels() - { - Iterator<Map<String, String>> iter = new CartesianProductField<String>( - "children", Arrays.asList("1", "2"), - new CartesianProductBase<String>( - "animal", Arrays.asList("cat", "dog"))); - - Assert.assertEquals(iter.hasNext(), true); - Map<String, String> map = iter.next(); - Assert.assertEquals(map.size(), 2); - Assert.assertTrue(map.containsKey("animal")); - Assert.assertTrue(map.containsKey("children")); - Assert.assertEquals(map.get("animal"), "cat"); - Assert.assertEquals(map.get("children"), "1"); - - Assert.assertEquals(iter.hasNext(), true); - map = iter.next(); - Assert.assertEquals(map.size(), 2); - Assert.assertTrue(map.containsKey("animal")); - Assert.assertTrue(map.containsKey("children")); - Assert.assertEquals(map.get("animal"), "cat"); - Assert.assertEquals(map.get("children"), "2"); - - Assert.assertEquals(iter.hasNext(), true); - map = iter.next(); - Assert.assertEquals(map.size(), 2); - Assert.assertTrue(map.containsKey("animal")); - Assert.assertTrue(map.containsKey("children")); - Assert.assertEquals(map.get("animal"), "dog"); - Assert.assertEquals(map.get("children"), "1"); - - Assert.assertEquals(iter.hasNext(), true); - map = iter.next(); - Assert.assertEquals(map.size(), 2); - Assert.assertTrue(map.containsKey("animal")); - Assert.assertTrue(map.containsKey("children")); - Assert.assertEquals(map.get("animal"), "dog"); - Assert.assertEquals(map.get("children"), "2"); - - Assert.assertFalse(iter.hasNext()); - Assert.assertFalse(iter.hasNext()); - Assert.assertFalse(iter.hasNext()); - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestAlwaysTrueRule.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestAlwaysTrueRule.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestAlwaysTrueRule.java deleted file mode 100644 index c32fa1b..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestAlwaysTrueRule.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules; - -import org.junit.Assert; -import org.junit.Test; - -public class TestAlwaysTrueRule -{ - - @Test - public void testRuleMatches() - { - Rule rule = new AlwaysTrueRule(); - Assert.assertTrue(rule.ruleMatches(null)); - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestAndRule.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestAndRule.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestAndRule.java deleted file mode 100644 index b930c38..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestAndRule.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules; - -import org.junit.Assert; -import org.junit.Test; - -public class TestAndRule -{ - - @Test - public void testRuleMatches() - { - Rule rule = new AndRule( - new AlwaysTrueRule(), - new AlwaysTrueRule()); - Assert.assertTrue(rule.ruleMatches(null)); - - rule = new AndRule( - new AlwaysTrueRule(), - new NotRule( - new AlwaysTrueRule())); - Assert.assertFalse(rule.ruleMatches(null)); - - rule = new AndRule( - new NotRule( - new AlwaysTrueRule()), - new AlwaysTrueRule()); - Assert.assertFalse(rule.ruleMatches(null)); - - rule = new AndRule( - new NotRule( - new AlwaysTrueRule()), - new NotRule( - new AlwaysTrueRule())); - Assert.assertFalse(rule.ruleMatches(null)); - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestFieldPredicate.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestFieldPredicate.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestFieldPredicate.java deleted file mode 100644 index 88cae45..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestFieldPredicate.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules; - -import java.util.Map; - -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; -import org.junit.Assert; -import org.junit.Test; - -import com.google.common.collect.ImmutableMap; - -public class TestFieldPredicate -{ - - @Test - public void testRuleMatches() - { - Map<String, Object> fields = ImmutableMap.of("brand", (Object) "Chef Corgi", - "flavor", (Object) "chicken"); - Product product = new Product(fields); - - Rule rule = new FieldPredicate("brand", "Chef Corgi"); - Assert.assertTrue(rule.ruleMatches(product)); - - rule = new FieldPredicate("brand", "Happy Pup"); - Assert.assertFalse(rule.ruleMatches(product)); - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestNotRule.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestNotRule.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestNotRule.java deleted file mode 100644 index ee284af..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestNotRule.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules; - -import org.junit.Assert; -import org.junit.Test; - -public class TestNotRule -{ - - @Test - public void testRuleMatches() - { - Rule rule = new NotRule( - new AlwaysTrueRule()); - Assert.assertFalse(rule.ruleMatches(null)); - - rule = new NotRule( - new NotRule( - new AlwaysTrueRule())); - Assert.assertTrue(rule.ruleMatches(null)); - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestOrRule.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestOrRule.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestOrRule.java deleted file mode 100644 index fd6f817..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/TestOrRule.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules; - -import org.junit.Assert; -import org.junit.Test; - -public class TestOrRule -{ - - @Test - public void testRuleMatches() - { - Rule rule = new OrRule( - new AlwaysTrueRule(), - new AlwaysTrueRule()); - Assert.assertTrue(rule.ruleMatches(null)); - - rule = new OrRule( - new AlwaysTrueRule(), - new NotRule( - new AlwaysTrueRule())); - Assert.assertTrue(rule.ruleMatches(null)); - - rule = new OrRule( - new NotRule( - new AlwaysTrueRule()), - new AlwaysTrueRule()); - Assert.assertTrue(rule.ruleMatches(null)); - - rule = new OrRule( - new NotRule( - new AlwaysTrueRule()), - new NotRule( - new AlwaysTrueRule())); - Assert.assertFalse(rule.ruleMatches(null)); - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestProductCategoryMarkovModelSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestProductCategoryMarkovModelSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestProductCategoryMarkovModelSampler.java deleted file mode 100644 index acb0929..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestProductCategoryMarkovModelSampler.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.purchase; - -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.apache.bigtop.bigpetstore.datagenerator.Constants; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory; -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; -import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovModel; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.UniformSampler; -import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductCategoryBuilder; -import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.MarkovModelProductCategorySampler; -import org.junit.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; - -public class TestProductCategoryMarkovModelSampler -{ - - private List<ProductCategory> createProducts() - { - List<ProductCategory> productCategories = Lists.newArrayList(); - - ProductCategoryBuilder foodBuilder = new ProductCategoryBuilder(); - foodBuilder.addApplicableSpecies(PetSpecies.DOG); - foodBuilder.setAmountUsedPetPetAverage(1.0); - foodBuilder.setAmountUsedPetPetVariance(1.0); - foodBuilder.setDailyUsageRate(2.0); - foodBuilder.setCategory("dogFood"); - foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood", - Constants.PRODUCT_QUANTITY, (Object) 60.0, "Flavor", "Fish & Potato"))); - foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood", - Constants.PRODUCT_QUANTITY, (Object) 30.0, "Flavor", "Chicken & Rice"))); - foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood", - Constants.PRODUCT_QUANTITY, (Object) 15.0, "Flavor", "Lamb & Barley"))); - productCategories.add(foodBuilder.build()); - - ProductCategoryBuilder bagBuilder = new ProductCategoryBuilder(); - bagBuilder.addApplicableSpecies(PetSpecies.DOG); - bagBuilder.setAmountUsedPetPetAverage(1.0); - bagBuilder.setAmountUsedPetPetVariance(1.0); - bagBuilder.setDailyUsageRate(2.0); - bagBuilder.setCategory("Poop Bags"); - bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags", - Constants.PRODUCT_QUANTITY, (Object) 60.0, "Color", "Blue"))); - bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags", - Constants.PRODUCT_QUANTITY, (Object) 30.0, "Color", "Red"))); - bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags", - Constants.PRODUCT_QUANTITY, (Object) 120.0, "Flavor", "Multicolor"))); - productCategories.add(bagBuilder.build()); - - return productCategories; - } - - @Test - public void testSample() throws Exception - { - SeedFactory seedFactory = new SeedFactory(1245); - - List<ProductCategory> productCategories = createProducts(); - - ProductCategory productCategory = productCategories.get(0); - - Sampler<Double> fieldWeightSampler = new UniformSampler(seedFactory); - - Map<String, Double> fieldWeights = Maps.newHashMap(); - for(String fieldName : productCategory.getFieldNames()) - { - fieldWeights.put(fieldName, fieldWeightSampler.sample()); - } - - MarkovModelProductCategorySampler generator = new MarkovModelProductCategorySampler(productCategory, - fieldWeights, new UniformSampler(seedFactory), new UniformSampler(seedFactory) - ); - - MarkovModel<Product> model = generator.sample(); - - assertNotNull(model); - assertNotNull(model.getStartWeights()); - assertNotNull(model.getTransitionWeights()); - assertTrue(model.getStartWeights().size() > 0); - assertTrue(model.getTransitionWeights().size() > 0); - } - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSampler.java deleted file mode 100644 index 12efe13..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSampler.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.purchase; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.apache.bigtop.bigpetstore.datagenerator.Constants; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory; -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; -import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductCategoryBuilder; -import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.MarkovPurchasingModel; -import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.PurchasingModelSamplerBuilder; -import org.junit.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; - -public class TestPurchasingModelSampler -{ - - private List<ProductCategory> createProducts() - { - List<ProductCategory> productCategories = Lists.newArrayList(); - - ProductCategoryBuilder foodBuilder = new ProductCategoryBuilder(); - foodBuilder.addApplicableSpecies(PetSpecies.DOG); - foodBuilder.setAmountUsedPetPetAverage(1.0); - foodBuilder.setAmountUsedPetPetVariance(1.0); - foodBuilder.setDailyUsageRate(2.0); - foodBuilder.setCategory("dogFood"); - foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood", - Constants.PRODUCT_QUANTITY, (Object) 60.0, "Flavor", "Fish & Potato"))); - foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood", - Constants.PRODUCT_QUANTITY, (Object) 30.0, "Flavor", "Chicken & Rice"))); - foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood", - Constants.PRODUCT_QUANTITY, (Object) 15.0, "Flavor", "Lamb & Barley"))); - productCategories.add(foodBuilder.build()); - - ProductCategoryBuilder bagBuilder = new ProductCategoryBuilder(); - bagBuilder.addApplicableSpecies(PetSpecies.DOG); - bagBuilder.setAmountUsedPetPetAverage(1.0); - bagBuilder.setAmountUsedPetPetVariance(1.0); - bagBuilder.setDailyUsageRate(2.0); - bagBuilder.setCategory("Poop Bags"); - bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags", - Constants.PRODUCT_QUANTITY, (Object) 60.0, "Color", "Blue"))); - bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags", - Constants.PRODUCT_QUANTITY, (Object) 30.0, "Color", "Red"))); - bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags", - Constants.PRODUCT_QUANTITY, (Object) 120.0, "Color", "Multicolor"))); - productCategories.add(bagBuilder.build()); - - return productCategories; - } - - @Test - public void testSample() throws Exception - { - SeedFactory seedFactory = new SeedFactory(1245); - - List<ProductCategory> productCategories = createProducts(); - - PurchasingModelSamplerBuilder builder = new PurchasingModelSamplerBuilder(productCategories, seedFactory); - Sampler<MarkovPurchasingModel> sampler = builder.buildMarkovPurchasingModel(); - MarkovPurchasingModel profile = sampler.sample(); - - assertNotNull(profile); - assertNotNull(profile.getProductCategories()); - assertTrue(profile.getProductCategories().size() > 0); - - for(String label : profile.getProductCategories()) - { - assertNotNull(profile.getProfile(label)); - assertNotNull(profile.getProfile(label).getStartWeights()); - assertTrue(profile.getProfile(label).getStartWeights().size() > 0); - assertNotNull(profile.getProfile(label).getTransitionWeights()); - assertTrue(profile.getProfile(label).getTransitionWeights().size() > 0); - } - } - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSamplerBuilder.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSamplerBuilder.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSamplerBuilder.java deleted file mode 100644 index 2d526ed..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSamplerBuilder.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.purchase; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.apache.bigtop.bigpetstore.datagenerator.Constants; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory; -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; -import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductCategoryBuilder; -import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.MarkovPurchasingModel; -import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.PurchasingModelSamplerBuilder; -import org.junit.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; - -public class TestPurchasingModelSamplerBuilder -{ - - private List<ProductCategory> createProducts() - { - List<ProductCategory> productCategories = Lists.newArrayList(); - - ProductCategoryBuilder foodBuilder = new ProductCategoryBuilder(); - foodBuilder.addApplicableSpecies(PetSpecies.DOG); - foodBuilder.setAmountUsedPetPetAverage(1.0); - foodBuilder.setAmountUsedPetPetVariance(1.0); - foodBuilder.setDailyUsageRate(2.0); - foodBuilder.setCategory("dogFood"); - foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood", - Constants.PRODUCT_QUANTITY, (Object) 60.0, "Flavor", "Fish & Potato"))); - foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood", - Constants.PRODUCT_QUANTITY, (Object) 30.0, "Flavor", "Chicken & Rice"))); - foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood", - Constants.PRODUCT_QUANTITY, (Object) 15.0, "Flavor", "Lamb & Barley"))); - productCategories.add(foodBuilder.build()); - - ProductCategoryBuilder bagBuilder = new ProductCategoryBuilder(); - bagBuilder.addApplicableSpecies(PetSpecies.DOG); - bagBuilder.setAmountUsedPetPetAverage(1.0); - bagBuilder.setAmountUsedPetPetVariance(1.0); - bagBuilder.setDailyUsageRate(2.0); - bagBuilder.setCategory("Poop Bags"); - bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags", - Constants.PRODUCT_QUANTITY, (Object) 60.0, "Color", "Blue"))); - bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags", - Constants.PRODUCT_QUANTITY, (Object) 30.0, "Color", "Red"))); - bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags", - Constants.PRODUCT_QUANTITY, (Object) 120.0, "Color", "Multicolor"))); - productCategories.add(bagBuilder.build()); - - return productCategories; - } - - @Test - public void testBuild() throws Exception - { - SeedFactory seedFactory = new SeedFactory(1245); - - List<ProductCategory> productCategories = createProducts(); - - PurchasingModelSamplerBuilder builder = new PurchasingModelSamplerBuilder(productCategories, seedFactory); - Sampler<MarkovPurchasingModel> sampler = builder.buildMarkovPurchasingModel(); - MarkovPurchasingModel profile = sampler.sample(); - - assertNotNull(profile); - assertNotNull(profile.getProductCategories()); - assertTrue(profile.getProductCategories().size() > 0); - - for(String label : profile.getProductCategories()) - { - assertNotNull(profile.getProfile(label)); - assertNotNull(profile.getProfile(label).getStartWeights()); - assertTrue(profile.getProfile(label).getStartWeights().size() > 0); - assertNotNull(profile.getProfile(label).getTransitionWeights()); - assertTrue(profile.getProfile(label).getTransitionWeights().size() > 0); - } - } - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingProcesses.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingProcesses.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingProcesses.java deleted file mode 100644 index c110def..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingProcesses.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.purchase; - -import static org.junit.Assert.assertNotNull; - -import java.util.Map; - -import org.apache.bigtop.bigpetstore.datagenerator.Constants; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.RouletteWheelSampler; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; -import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.PurchasingProcesses; -import org.junit.Test; - -import com.google.common.collect.Maps; - -public class TestPurchasingProcesses -{ - - @Test - public void testSimulatePurchase() throws Exception - { - Map<Product, Double> productPDF = Maps.newHashMap(); - - for(int i = 0; i < 10; i++) - { - Map<String, Object> fields = Maps.newHashMap(); - fields.put(Constants.PRODUCT_CATEGORY, "dog food"); - fields.put(Constants.PRODUCT_QUANTITY, (double) (i + 1)); - Product product = new Product(fields); - productPDF.put(product, 0.1); - } - - SeedFactory seedFactory = new SeedFactory(1234); - Sampler<Product> sampler = RouletteWheelSampler.create(productPDF, seedFactory); - - - Map<String, Sampler<Product>> processesMap = Maps.newHashMap(); - processesMap.put("dog food", sampler); - PurchasingProcesses processes = new PurchasingProcesses(processesMap); - - Product product = processes.sample("dog food"); - - assertNotNull(product); - assertNotNull(product.getFieldValue(Constants.PRODUCT_CATEGORY)); - assertNotNull(product.getFieldValue(Constants.PRODUCT_QUANTITY)); - - product = processes.sample("dog food"); - - assertNotNull(product); - assertNotNull(product.getFieldValue(Constants.PRODUCT_CATEGORY)); - assertNotNull(product.getFieldValue(Constants.PRODUCT_QUANTITY)); - } - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreLocationIncomePDF.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreLocationIncomePDF.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreLocationIncomePDF.java deleted file mode 100644 index f9b8126..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreLocationIncomePDF.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.store; - -import static org.junit.Assert.assertTrue; - -import java.util.Arrays; -import java.util.List; - -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord; -import org.apache.commons.lang3.tuple.Pair; -import org.junit.Test; - -public class TestStoreLocationIncomePDF -{ - - @Test - public void testProbability() throws Exception - { - List<ZipcodeRecord> zipcodes = Arrays.asList(new ZipcodeRecord[] { - new ZipcodeRecord("11111", Pair.of(1.0, 1.0), "AZ", "Tempte", 30000.0, 100), - new ZipcodeRecord("22222", Pair.of(2.0, 2.0), "AZ", "Phoenix", 45000.0, 200), - new ZipcodeRecord("33333", Pair.of(3.0, 3.0), "AZ", "Flagstaff", 60000.0, 300) - }); - - StoreLocationIncomePDF pdf = new StoreLocationIncomePDF(zipcodes, 100.0); - - for(ZipcodeRecord record : zipcodes) - { - assertTrue(pdf.probability(record) > 0.0); - } - - } - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreLocationPopulationPDF.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreLocationPopulationPDF.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreLocationPopulationPDF.java deleted file mode 100644 index 792f6d0..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreLocationPopulationPDF.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.store; - -import static org.junit.Assert.assertTrue; - -import java.util.Arrays; -import java.util.List; - -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord; -import org.apache.commons.lang3.tuple.Pair; -import org.junit.Test; - -public class TestStoreLocationPopulationPDF -{ - - @Test - public void testProbability() throws Exception - { - List<ZipcodeRecord> zipcodes = Arrays.asList(new ZipcodeRecord[] { - new ZipcodeRecord("11111", Pair.of(1.0, 1.0), "AZ", "Tempte", 30000.0, 100), - new ZipcodeRecord("22222", Pair.of(2.0, 2.0), "AZ", "Phoenix", 45000.0, 200), - new ZipcodeRecord("33333", Pair.of(3.0, 3.0), "AZ", "Flagstaff", 60000.0, 300) - }); - - StoreLocationPopulationPDF pdf = new StoreLocationPopulationPDF(zipcodes); - - for(ZipcodeRecord record : zipcodes) - { - assertTrue(pdf.probability(record) > 0.0); - } - - } - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreSampler.java deleted file mode 100644 index 64589f4..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/store/TestStoreSampler.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.store; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.Arrays; -import java.util.Collection; - -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Store; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord; -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.RouletteWheelSampler; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.SequenceSampler; -import org.apache.commons.lang3.tuple.Pair; -import org.junit.Test; - -public class TestStoreSampler -{ - - @Test - public void testSampler() throws Exception - { - Collection<ZipcodeRecord> zipcodes = Arrays.asList(new ZipcodeRecord[] { - new ZipcodeRecord("11111", Pair.of(1.0, 1.0), "AZ", "Tempte", 30000.0, 100), - new ZipcodeRecord("22222", Pair.of(2.0, 2.0), "AZ", "Phoenix", 45000.0, 200), - new ZipcodeRecord("33333", Pair.of(3.0, 3.0), "AZ", "Flagstaff", 60000.0, 300) - }); - - SeedFactory factory = new SeedFactory(1234); - - Sampler<Store> sampler = new StoreSampler(new SequenceSampler(), - RouletteWheelSampler.createUniform(zipcodes, factory)); - - Store store = sampler.sample(); - assertNotNull(store); - assertTrue(store.getId() >= 0); - assertNotNull(store.getName()); - assertNotNull(store.getLocation()); - - } - -}
