public void TestCreateMultiNodeTreeFromScratch() { ProductPartitionTree tree = ProductPartitionTree.CreateAdGroupTree(new List <AdGroupCriterion>()); ProductPartitionNode rootNode = tree.Root.AsSubdivision(); ProductPartitionNode brand1 = rootNode.AddChild(ProductDimensions.CreateBrand("google")) .AsSubdivision(); ProductPartitionNode brand1Offer1 = brand1.AddChild(ProductDimensions.CreateOfferId("A")); brand1Offer1.AsBiddableUnit().CpcBid = 1000000L; ProductPartitionNode brand1Offer2 = brand1.AddChild(ProductDimensions.CreateOfferId()).AsExcludedUnit(); ProductPartitionNode brand2 = rootNode.AddChild(ProductDimensions.CreateBrand()).AsExcludedUnit(); ProductPartitionNode[] nodes = new ProductPartitionNode[] { rootNode, brand1, brand1Offer1, brand1Offer2, brand2 }; AdGroupCriterionOperation[] mutateOperations = tree.GetMutateOperations(); for (int i = 0; i < nodes.Length; i++) { List <AdGroupCriterionOperation> nodeOperations = shoppingTestUtils.GetOperationsForNode(nodes[i], mutateOperations); Assert.That(nodeOperations.Count == 1); Assert.That(nodeOperations[0].@operator == Operator.ADD); ProductPartition partition = (ProductPartition)nodeOperations[0].operand.criterion; Assert.That(partition.id == nodes[i].ProductPartitionId); if (nodes[i].Parent == null) { Assert.That(partition.parentCriterionIdSpecified == false); } else { Assert.That(partition.parentCriterionId == nodes[i].Parent.ProductPartitionId); } Assert.That(partition.caseValue == nodes[i].Dimension); } }
public void TestCreateOfferId() { ProductOfferId productOfferIdA = new ProductOfferId() { value = "google" }; ProductOfferId productOfferIdB = ProductDimensions.CreateOfferId("google"); Assert.True(comparer.Equals(productOfferIdA, productOfferIdB)); ProductOfferId productOfferIdC = new ProductOfferId() { }; ProductOfferId productOfferIdD = ProductDimensions.CreateOfferId(); Assert.True(comparer.Equals(productOfferIdC, productOfferIdD)); }
public void TestCreateUltimatelyEmptyTree() { ProductPartitionTree tree = ProductPartitionTree.CreateAdGroupTree(new List <AdGroupCriterion>()); ProductPartitionNode rootNode = tree.Root.AsSubdivision(); ProductPartitionNode brand1 = rootNode.AddChild(ProductDimensions.CreateBrand("google")) .AsSubdivision(); ProductPartitionNode offerNode = brand1.AddChild(ProductDimensions.CreateOfferId("A")); offerNode.AsBiddableUnit().CpcBid = 1000000L; brand1.AddChild(ProductDimensions.CreateOfferId()).AsExcludedUnit(); ProductPartitionNode brand2 = rootNode.AddChild(ProductDimensions.CreateBrand()).AsExcludedUnit(); // Now remove the two child nodes under the root and set the root back // to a UNIT. This should result in operations that simply create the // root node. rootNode.RemoveChild(brand1.Dimension); rootNode.RemoveChild(brand2.Dimension); rootNode = rootNode.AsBiddableUnit(); AdGroupCriterionOperation[] mutateOperations = tree.GetMutateOperations(); Assert.AreEqual(mutateOperations.Count(), 1, "Number of operations is incorrect."); AdGroupCriterionOperation operation = mutateOperations[0]; Assert.AreEqual(Operator.ADD, operation.@operator, "Should have a single operation to ADD the root node."); BiddableAdGroupCriterion adGroupCriterion = (BiddableAdGroupCriterion)operation.operand; Assert.Null(((ProductPartition)adGroupCriterion.criterion).caseValue, "Product dimension of operation's operand should be null."); Assert.True(adGroupCriterion.criterion.id < 0L, "Partition ID of the operand should be negative."); }
/// <summary> /// Subdivides the new shoes. /// </summary> /// Takes a tree with: /// <pre> /// ROOT /// ... /// shoes /// new some bid /// </pre> /// /// and changes it to: /// /// <pre> /// ROOT /// ... /// shoes /// new /// other offerId $1.00 /// offerId=2 $2.00 /// ... /// offerId=20 $20.00 /// </pre> private void SubdivideNewShoes() { ProductPartitionNode shoesLevel1 = tree.Root.GetChild(ProductDimensions.CreateType( ProductDimensionType.PRODUCT_TYPE_L1, "shoes")).AsSubdivision(); ProductPartitionNode newShoesLevel2 = shoesLevel1.GetChild( ProductDimensions.CreateCanonicalCondition(ProductCanonicalConditionCondition.NEW)) .AsSubdivision(); for (int i = 1; i <= 20; i++) { ProductOfferId offerId = ProductDimensions.CreateOfferId(); if (i > 1) { offerId.value = i.ToString(); } newShoesLevel2.AddChild(offerId).AsBiddableUnit().CpcBid = i * 1000000L; } Assert.DoesNotThrow(delegate() { tree = ExecuteTreeOperations(); }); }