Repository: bigtop
Updated Branches:
  refs/heads/master 92bd68306 -> 5646c87d7


http://git-wip-us.apache.org/repos/asf/bigtop/blob/5646c87d/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSampler.java
----------------------------------------------------------------------
diff --git 
a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSampler.java
 
b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSampler.java
new file mode 100644
index 0000000..49fa16d
--- /dev/null
+++ 
b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSampler.java
@@ -0,0 +1,47 @@
+/**
+ * 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.transaction;
+
+import static org.junit.Assert.assertTrue;
+
+import org.apache.bigtop.bigpetstore.datagenerator.Constants;
+import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
+import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
+import 
org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParameters;
+import 
org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParametersSamplerBuilder;
+import org.junit.Test;
+
+public class TestCustomerTransactionParametersSampler
+{
+
+       @Test
+       public void testSample() throws Exception
+       {
+               SeedFactory seedFactory = new SeedFactory(1234);
+               CustomerTransactionParametersSamplerBuilder builder = new 
CustomerTransactionParametersSamplerBuilder(seedFactory);
+               Sampler<CustomerTransactionParameters> sampler = 
builder.build();
+               
+               CustomerTransactionParameters transParams = sampler.sample();
+               
+               assertTrue(transParams.countPets() >= Constants.MIN_PETS);
+               assertTrue(transParams.countPets() <= Constants.MAX_PETS);
+               assertTrue(transParams.getAveragePurchaseTriggerTime() >= 
Constants.PURCHASE_TRIGGER_TIME_MIN);
+               assertTrue(transParams.getAveragePurchaseTriggerTime() <= 
Constants.PURCHASE_TRIGGER_TIME_MAX);
+               assertTrue(transParams.getAverageTransactionTriggerTime() >= 
Constants.TRANSACTION_TRIGGER_TIME_MIN);
+               assertTrue(transParams.getAverageTransactionTriggerTime() <= 
Constants.TRANSACTION_TRIGGER_TIME_MAX);
+       }
+
+}

http://git-wip-us.apache.org/repos/asf/bigtop/blob/5646c87d/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSamplerBuilder.java
----------------------------------------------------------------------
diff --git 
a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSamplerBuilder.java
 
b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSamplerBuilder.java
new file mode 100644
index 0000000..fbe4e08
--- /dev/null
+++ 
b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerTransactionParametersSamplerBuilder.java
@@ -0,0 +1,47 @@
+/**
+ * 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.transaction;
+
+import static org.junit.Assert.assertTrue;
+
+import org.apache.bigtop.bigpetstore.datagenerator.Constants;
+import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
+import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
+import 
org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParameters;
+import 
org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParametersSamplerBuilder;
+import org.junit.Test;
+
+public class TestCustomerTransactionParametersSamplerBuilder
+{
+
+       @Test
+       public void testBuild() throws Exception
+       {
+               SeedFactory seedFactory = new SeedFactory(1234);
+               CustomerTransactionParametersSamplerBuilder builder = new 
CustomerTransactionParametersSamplerBuilder(seedFactory);
+               Sampler<CustomerTransactionParameters> sampler = 
builder.build();
+               
+               CustomerTransactionParameters transParams = sampler.sample();
+               
+               assertTrue(transParams.countPets() >= Constants.MIN_PETS);
+               assertTrue(transParams.countPets() <= Constants.MAX_PETS);
+               assertTrue(transParams.getAveragePurchaseTriggerTime() >= 
Constants.PURCHASE_TRIGGER_TIME_MIN);
+               assertTrue(transParams.getAveragePurchaseTriggerTime() <= 
Constants.PURCHASE_TRIGGER_TIME_MAX);
+               assertTrue(transParams.getAverageTransactionTriggerTime() >= 
Constants.TRANSACTION_TRIGGER_TIME_MIN);
+               assertTrue(transParams.getAverageTransactionTriggerTime() <= 
Constants.TRANSACTION_TRIGGER_TIME_MAX);
+       }
+
+}

http://git-wip-us.apache.org/repos/asf/bigtop/blob/5646c87d/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryInventory.java
----------------------------------------------------------------------
diff --git 
a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryInventory.java
 
b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryInventory.java
new file mode 100644
index 0000000..121f08c
--- /dev/null
+++ 
b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryInventory.java
@@ -0,0 +1,75 @@
+/**
+ * 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.transaction;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Map;
+
+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.datamodels.inputs.ProductCategoryBuilder;
+import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
+import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler;
+import 
org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParameters;
+import 
org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParametersSamplerBuilder;
+import 
org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.ProductCategoryInventory;
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+
+public class TestProductCategoryInventory
+{
+       
+       @Test
+       public void testPurchase() throws Exception
+       {
+               SeedFactory seedFactory = new SeedFactory(1234);
+               
+               CustomerTransactionParametersSamplerBuilder transParamsBuilder 
= new CustomerTransactionParametersSamplerBuilder(seedFactory);
+               Sampler<CustomerTransactionParameters> sampler = 
transParamsBuilder.build();
+               
+               CustomerTransactionParameters parameters = sampler.sample();
+               
+               ProductCategoryBuilder builder = new ProductCategoryBuilder();
+               builder.addApplicableSpecies(PetSpecies.DOG);
+               builder.setAmountUsedPetPetAverage(1.0);
+               builder.setAmountUsedPetPetVariance(1.0);
+               builder.setDailyUsageRate(2.0);
+               
+               
+               ProductCategory category = builder.build();
+               
+               ProductCategoryInventory inventory = new 
ProductCategoryInventory(category, parameters, seedFactory);
+               
+               assertEquals(inventory.findExhaustionTime(), 0.0, 0.0001);
+               assertEquals(inventory.findRemainingAmount(0.0), 0.0, 0.0001);
+               
+               Map<String, Object> fields = Maps.newHashMap();
+               fields.put(Constants.PRODUCT_CATEGORY, "dog food");
+               fields.put(Constants.PRODUCT_QUANTITY, 30.0);
+               Product product = new Product(fields);
+               
+               inventory.simulatePurchase(1.0, product);
+               
+               assertTrue(inventory.findExhaustionTime() > 1.0);
+               assertTrue(inventory.findRemainingAmount(1.0) > 0.0);
+       }
+
+}

http://git-wip-us.apache.org/repos/asf/bigtop/blob/5646c87d/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageSimulator.java
----------------------------------------------------------------------
diff --git 
a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageSimulator.java
 
b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageSimulator.java
new file mode 100644
index 0000000..267cd00
--- /dev/null
+++ 
b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageSimulator.java
@@ -0,0 +1,53 @@
+/**
+ * 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.transaction;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Pair;
+import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory;
+import 
org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.ProductCategoryUsageSimulator;
+import 
org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.ProductCategoryUsageTrajectory;
+import org.junit.Test;
+
+public class TestProductCategoryUsageSimulator
+{
+       
+       @Test
+       public void testSimulate() throws Exception
+       {
+               SeedFactory seedFactory = new SeedFactory(1234);
+               
+               ProductCategoryUsageSimulator simulator = new 
ProductCategoryUsageSimulator(2.0, 1.0, 1.0, seedFactory);
+               
+               ProductCategoryUsageTrajectory trajectory = 
simulator.simulate(0.0, 30.0);
+               
+               assertEquals(0.0, trajectory.getLastAmount(), 0.0001);
+               
+               Pair<Double, Double> previousEntry = trajectory.getStep(0);
+               for(int i = 1; i < trajectory.size(); i++)
+               {
+                       Pair<Double, Double> entry = trajectory.getStep(i);
+                       // time should move forward
+                       assertTrue(previousEntry.getFirst() <= 
entry.getFirst());
+                       // remaining amounts should go down
+                       assertTrue(previousEntry.getSecond() >= 
entry.getSecond());
+                       previousEntry = entry;
+               }
+       }
+
+}

http://git-wip-us.apache.org/repos/asf/bigtop/blob/5646c87d/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageTrajectory.java
----------------------------------------------------------------------
diff --git 
a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageTrajectory.java
 
b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageTrajectory.java
new file mode 100644
index 0000000..e7bb982
--- /dev/null
+++ 
b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryUsageTrajectory.java
@@ -0,0 +1,70 @@
+/**
+ * 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.transaction;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Pair;
+import 
org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.ProductCategoryUsageTrajectory;
+import org.junit.Test;
+
+public class TestProductCategoryUsageTrajectory
+{
+       
+       @Test
+       public void testTrajectory()
+       {
+               double initialAmount = 30.0;
+               double initialTime = 0.0;
+               
+               ProductCategoryUsageTrajectory trajectory = new 
ProductCategoryUsageTrajectory(initialTime, initialAmount);
+               
+               assertEquals(trajectory.size(), 1);
+               
+               Pair<Double, Double> entry = trajectory.getStep(0);
+               assertEquals(initialTime, entry.getFirst(), 0.0001);
+               assertEquals(initialAmount, entry.getSecond(), 0.0001);
+               
+               trajectory.append(1.0, 25.0);
+               
+               assertEquals(2, trajectory.size());
+               
+               entry = trajectory.getStep(1);
+               assertEquals(1.0, entry.getFirst(), 0.0001);
+               assertEquals(25.0, entry.getSecond(), 0.0001);
+               
+               assertEquals(1.0, trajectory.getLastTime(), 0.0001);
+               assertEquals(25.0, trajectory.getLastAmount(), 0.0001);
+       }
+       
+       @Test
+       public void testAmountAtTime()
+       {
+               ProductCategoryUsageTrajectory trajectory = new 
ProductCategoryUsageTrajectory(0.0, 30.0);
+               trajectory.append(1.0, 25.0);
+               trajectory.append(2.0, 20.0);
+               trajectory.append(3.0, 50.0);
+               trajectory.append(4.0, 40.0);
+               trajectory.append(4.0, 50.0);
+               trajectory.append(5.0, 30.0);
+               
+               assertEquals(30.0, trajectory.amountAtTime(0.5), 0.0001);
+               assertEquals(50.0, trajectory.amountAtTime(4.0), 0.0001);
+               assertEquals(30.0, trajectory.amountAtTime(10.0), 0.0001);
+       }
+
+
+}

http://git-wip-us.apache.org/repos/asf/bigtop/blob/5646c87d/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionPurchasesHiddenMarkovModel.java
----------------------------------------------------------------------
diff --git 
a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionPurchasesHiddenMarkovModel.java
 
b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionPurchasesHiddenMarkovModel.java
new file mode 100644
index 0000000..9d89410
--- /dev/null
+++ 
b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionPurchasesHiddenMarkovModel.java
@@ -0,0 +1,205 @@
+/**
+ * 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.transaction;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+import java.util.Map;
+
+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.datamodels.inputs.ProductCategoryBuilder;
+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.samplers.Sampler;
+import 
org.apache.bigtop.bigpetstore.datagenerator.framework.wfs.ConditionalWeightFunction;
+import 
org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.MarkovPurchasingModel;
+import 
org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.PurchasingProcesses;
+import 
org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CategoryWeightFunction;
+import 
org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerInventory;
+import 
org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerInventoryBuilder;
+import 
org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParameters;
+import 
org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParametersSamplerBuilder;
+import 
org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.TransactionPurchasesHiddenMarkovModel;
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+public class TestTransactionPurchasesHiddenMarkovModel
+{
+       
+       private List<Product> createProducts(String category)
+       {
+               List<Product> products = Lists.newArrayList();
+               
+               for(int i = 0; i < 10; i++)
+               {
+                       Map<String, Object> fields = Maps.newHashMap();
+                       fields.put(Constants.PRODUCT_CATEGORY, category);
+                       fields.put(Constants.PRODUCT_QUANTITY, (double) (i + 
1));
+                       Product product = new Product(fields);
+                       products.add(product);
+               }
+               
+               return products;
+       }
+       
+       private MarkovModel<Product> createMarkovModel(ProductCategory category)
+       {
+               MarkovModelBuilder<Product> markovBuilder = new 
MarkovModelBuilder<Product>();
+               
+               for(Product product1 : category.getProducts())
+               {
+                       markovBuilder.addStartState(product1, 1.0);
+                       for(Product product2 : category.getProducts())
+                       {
+                               markovBuilder.addTransition(product1, product2, 
1.0);
+                       }
+               }
+               
+               return markovBuilder.build();
+       }
+       
+       protected PurchasingProcesses createProcesses(ProductCategory 
dogFoodCategory,
+                       ProductCategory catFoodCategory, SeedFactory 
seedFactory)
+       {       
+               MarkovModel<Product> dogFoodModel = 
createMarkovModel(dogFoodCategory);
+               MarkovModel<Product> catFoodModel = 
createMarkovModel(catFoodCategory);
+               
+               Map<String, MarkovModel<Product>> models = Maps.newHashMap();
+               models.put("dog food", dogFoodModel);
+               models.put("cat food", catFoodModel);
+               
+               MarkovPurchasingModel profile = new 
MarkovPurchasingModel(models);
+               
+               return profile.buildProcesses(seedFactory);
+       }
+       
+       protected ProductCategory createCategory(String category)
+       {
+               List<Product> products = createProducts(category);
+               
+               ProductCategoryBuilder builder = new ProductCategoryBuilder();
+               
+               if(category.equals("dog food"))
+               {
+                       builder.addApplicableSpecies(PetSpecies.DOG);
+               }
+               else
+               {
+                       builder.addApplicableSpecies(PetSpecies.CAT);
+               }
+               
+               builder.setAmountUsedPetPetAverage(1.0);
+               builder.setAmountUsedPetPetVariance(1.0);
+               builder.setDailyUsageRate(2.0);
+               builder.setCategory(category);
+               builder.setTriggerPurchaseRate(1.0 / 10.0);
+               builder.setTriggerPurchaseRate(1.0 / 10.0);
+               
+               for(Product product : products)
+               {
+                       builder.addProduct(product);
+               }
+               
+               return builder.build();
+       }
+
+       protected TransactionPurchasesHiddenMarkovModel createHMM() throws 
Exception
+       {
+               SeedFactory seedFactory = new SeedFactory(1234);
+               
+               ProductCategory dogFoodCategory = createCategory("dog food");
+               ProductCategory catFoodCategory = createCategory("cat food");
+               
+               PurchasingProcesses processes = 
createProcesses(dogFoodCategory, catFoodCategory, seedFactory);
+               
+               CustomerTransactionParametersSamplerBuilder transParamsBuilder 
= new CustomerTransactionParametersSamplerBuilder(seedFactory);
+               Sampler<CustomerTransactionParameters> sampler = 
transParamsBuilder.build();
+               
+               CustomerTransactionParameters parameters = sampler.sample();
+               
+               CustomerInventoryBuilder inventoryBuilder = new 
CustomerInventoryBuilder(parameters, seedFactory);
+               inventoryBuilder.addProductCategory(dogFoodCategory);
+               inventoryBuilder.addProductCategory(catFoodCategory);
+               CustomerInventory inventory = inventoryBuilder.build();
+               
+               ConditionalWeightFunction<Double, Double> categoryWF =
+                               new 
CategoryWeightFunction(parameters.getAveragePurchaseTriggerTime());
+               
+               TransactionPurchasesHiddenMarkovModel hmm = new 
TransactionPurchasesHiddenMarkovModel(processes,
+                               categoryWF, inventory, seedFactory);
+               
+               return hmm;
+       }
+       
+       @Test
+       public void testChooseCategory() throws Exception
+       {
+               TransactionPurchasesHiddenMarkovModel hmm = createHMM();
+               
+               String category = hmm.chooseCategory(1.0, 0);
+               
+               assertNotNull(category);
+               
assertTrue(category.equals(TransactionPurchasesHiddenMarkovModel.STOP_STATE) ||
+                               category.equals("dog food") ||
+                               category.equals("cat food"));
+       }
+       
+       @Test
+       public void testChooseProduct() throws Exception
+       {
+               TransactionPurchasesHiddenMarkovModel hmm = createHMM();
+               
+               Product product = hmm.chooseProduct("dog food");
+               
+               assertNotNull(product);
+               
assertTrue(product.getFieldValue(Constants.PRODUCT_CATEGORY).equals("dog 
food"));
+               
+               product = hmm.chooseProduct("cat food");
+               
+               assertNotNull(product);
+               
assertTrue(product.getFieldValue(Constants.PRODUCT_CATEGORY).equals("cat 
food"));
+       }
+       
+       @Test
+       public void testSample() throws Exception
+       {       
+               TransactionPurchasesHiddenMarkovModel hmm = createHMM();
+               
+               List<Product> purchase = hmm.sample(1.0);
+               
+               assertTrue(purchase.size() > 0);
+               
+               for(int i = 0; i < purchase.size(); i++)
+               {
+                       Product product = purchase.get(i);
+                       
+                       // first product should never be null
+                       assertNotNull(product);
+                       
assertTrue(product.getFieldValue(Constants.PRODUCT_CATEGORY).equals("dog food") 
|| 
+                                       
product.getFieldValue(Constants.PRODUCT_CATEGORY).equals("cat food"));
+               }
+               
+       }
+
+}

http://git-wip-us.apache.org/repos/asf/bigtop/blob/5646c87d/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionTimePDF.java
----------------------------------------------------------------------
diff --git 
a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionTimePDF.java
 
b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionTimePDF.java
new file mode 100644
index 0000000..8c57f84
--- /dev/null
+++ 
b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionTimePDF.java
@@ -0,0 +1,46 @@
+/**
+ * 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.transaction;
+
+import static org.junit.Assert.assertEquals;
+
+import 
org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.TransactionTimePDF;
+import org.junit.Test;
+
+public class TestTransactionTimePDF
+{
+       
+       @Test
+       public void testProbability() throws Exception
+       {
+               TransactionTimePDF pdf = new TransactionTimePDF();
+               
+               assertEquals(pdf.probability(0.5, 0.75), 0.0, 0.000001);
+               assertEquals(pdf.probability(0.5, 0.5), 1.0, 0.000001);
+               assertEquals(pdf.probability(0.75, 0.5), 1.0, 0.000001);
+       }
+       
+       @Test
+       public void testFixConditional() throws Exception
+       {
+               TransactionTimePDF pdf = new TransactionTimePDF();
+               
+               assertEquals(pdf.fixConditional(0.75).probability(0.5), 0.0, 
0.000001);
+               assertEquals(pdf.fixConditional(0.5).probability(0.5), 1.0, 
0.000001);
+               assertEquals(pdf.fixConditional(0.5).probability(0.75), 1.0, 
0.000001);
+       }
+
+}

Reply via email to