diff --git a/AlgebraicDataflowArchitectureModel/src/tests/DataFlowModelTest.java b/AlgebraicDataflowArchitectureModel/src/tests/DataFlowModelTest.java index d2b8e9d..080a992 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/DataFlowModelTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/DataFlowModelTest.java @@ -12,35 +12,51 @@ @Test public void test() { - // Construct a dataflow architecture model. + // Construct a data-flow architecture model. DataFlowModel model = new DataFlowModel(); - IdentifierTemplate customer_off = new IdentifierTemplate(1); - IdentifierTemplate customer_add = new IdentifierTemplate(1); - IdentifierTemplate company_add = new IdentifierTemplate(1); + IdentifierTemplate customer_off = new IdentifierTemplate(1); // an identifier template to specify a customer's office resource + IdentifierTemplate company_add = new IdentifierTemplate(1); // an identifier template to specify a companie's address resource + IdentifierTemplate customer_add = new IdentifierTemplate(1); // an identifier template to specify a customer's address resource - DataflowChannelGenerator gin_1 = new DataflowChannelGenerator(); // set customer's office + // === gin_1 === + // + // {x1}.customer_off(c, set(x)) = x + // {x1}.customer_off(c, e) = c + // + DataflowChannelGenerator gin_1 = new DataflowChannelGenerator(); // set customer's office (an input channel) GroupSelector x1 = new GroupSelector(); ChannelMember customer_off_1 = new ChannelMember(customer_off); - customer_off_1.addSelector(x1); + customer_off_1.addSelector(x1); // x1 is determined by the path parameter in customer's office template, and serves as a group selector in this channel gin_1.addChannelMember(customer_off_1); assertEquals(customer_off.getNumberOfParameters(), customer_off_1.getSelectors().size()); - DataflowChannelGenerator gin_2 = new DataflowChannelGenerator(); // set companie's address + // === gin_2 === + // + // {x2}.company_add(a, set(y)) = y + // {x2}.company_add(a, e) = a + // + DataflowChannelGenerator gin_2 = new DataflowChannelGenerator(); // set companie's address (an input channel) GroupSelector x2 = new GroupSelector(); ChannelMember company_add_1 = new ChannelMember(company_add); - company_add_1.addSelector(x2); + company_add_1.addSelector(x2); // x2 is determined by the path parameter in companie's address template, and serves as a group selector in this channel gin_2.addChannelMember(company_add_1); assertEquals(company_add.getNumberOfParameters(), company_add_1.getSelectors().size()); + // === g === + // + // {x3}.customer_off( c, update(y, z)) = y + // {y}.company_add( a1, update(y, z)) = z + // {x3}.customer_add(a2, update(y, z)) = z + // DataflowChannelGenerator g = new DataflowChannelGenerator(); // update customer's address GroupSelector x3 = new GroupSelector(); ChannelSelector y = new ChannelSelector(); ChannelMember customer_off_2 = new ChannelMember(customer_off); ChannelMember company_add_2 = new ChannelMember(company_add); ChannelMember customer_add_2 = new ChannelMember(customer_add); - customer_off_2.addSelector(x3); - company_add_2.addSelector(y); - customer_add_2.addSelector(x3); + customer_off_2.addSelector(x3); // x3 is determined by the path parameter in customer's office template, and serves as a group selector in this channel + company_add_2.addSelector(y); // y is determined by the value of the customer's office resource, and serves as a channel selector in this channel + customer_add_2.addSelector(x3); // x3 determines the path parameter in customer's address template to update g.addChannelMemberAsInput(customer_off_2); g.addChannelMemberAsInput(customer_add_2); g.addChannelMemberAsOutput(company_add_2); @@ -48,6 +64,7 @@ assertEquals(customer_add.getNumberOfParameters(), customer_add_2.getSelectors().size()); assertEquals(company_add.getNumberOfParameters(), company_add_2.getSelectors().size()); + // Construct a data-flow architecture model. model.addIOChannelGenerator(gin_1); model.addIOChannelGenerator(gin_2); model.addChannelGenerator(g); diff --git a/AlgebraicDataflowArchitectureModel/src/tests/SimplifiedDataFlowModelTest.java b/AlgebraicDataflowArchitectureModel/src/tests/SimplifiedDataFlowModelTest.java new file mode 100644 index 0000000..4cc256d --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/tests/SimplifiedDataFlowModelTest.java @@ -0,0 +1,95 @@ +package tests; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import models.*; +import models.dataConstraintModel.*; +import models.dataFlowModel.*; + +public class SimplifiedDataFlowModelTest { + + @Test + public void test() { + // Construct a data-flow architecture model. + DataFlowModel model = new DataFlowModel(); + IdentifierTemplate payment = new IdentifierTemplate(0); // an identifier template to specify the payment resource + IdentifierTemplate loyalty = new IdentifierTemplate(0); // an identifier template to specify the loyalty resource + IdentifierTemplate history = new IdentifierTemplate(0); // an identifier template to specify the payment history resource + IdentifierTemplate total = new IdentifierTemplate(0); // an identifier template to specify the total payment resource + + // === cin === + // + // payment(p1, purchase(x)) = x + // + DataflowChannelGenerator cin = new DataflowChannelGenerator(); + ChannelMember cin_payment = new ChannelMember(payment); + cin.addChannelMember(cin_payment); + assertEquals(cin.getChannelMembers().size(), 1); + + // === c1 === + // + // payment(p1, update1(y)) = y + // loyalty(l, update1(y)) = floor(y * 0.05) + // + DataflowChannelGenerator c1 = new DataflowChannelGenerator(); + ChannelMember c1_payment = new ChannelMember(payment); + ChannelMember c1_loyalty = new ChannelMember(loyalty); + c1.addChannelMemberAsInput(c1_payment); + c1.addChannelMemberAsOutput(c1_loyalty); + assertEquals(c1.getChannelMembers().size(), 2); + assertEquals(c1.getInputChannelMembers().size(), 1); + assertEquals(c1.getOutputChannelMembers().size(), 1); + + // === c2 === + // + // payment(p1, update2(z)) = z + // history(h, update2(z)) = cons(z, h) + // + DataflowChannelGenerator c2 = new DataflowChannelGenerator(); + ChannelMember c2_payment = new ChannelMember(payment); + ChannelMember c2_history = new ChannelMember(history); + c2.addChannelMemberAsInput(c2_payment); + c2.addChannelMemberAsOutput(c2_history); + assertEquals(c2.getChannelMembers().size(), 2); + assertEquals(c2.getInputChannelMembers().size(), 1); + assertEquals(c2.getOutputChannelMembers().size(), 1); + + // === c3 === + // + // history(h, update3(u)) = u + // total(t, update3(u)) = sum(u) + // + DataflowChannelGenerator c3 = new DataflowChannelGenerator(); + ChannelMember c3_history = new ChannelMember(history); + ChannelMember c3_total = new ChannelMember(total); + c3.addChannelMemberAsInput(c3_history); + c3.addChannelMemberAsOutput(c3_total); + assertEquals(c3.getChannelMembers().size(), 2); + assertEquals(c3.getInputChannelMembers().size(), 1); + assertEquals(c3.getOutputChannelMembers().size(), 1); + + // Construct a data-flow architecture model. + model.addIOChannelGenerator(cin); + model.addChannelGenerator(c1); + model.addChannelGenerator(c2); + model.addChannelGenerator(c3); + + // Check the model. + assertEquals(4, model.getIdentifierTemplates().size()); + assertEquals(1, model.getIOChannelGenerators().size()); + assertEquals(3, model.getChannelGenerators().size()); + + // Extract the resource dependency graph. + ResourceDependencyGraph resourceDependencyGraph = model.getResourceDependencyGraph(); + + // Check the graph. + assertEquals(4, resourceDependencyGraph.getNodes().size()); + assertEquals(3, resourceDependencyGraph.getEdges().size()); + for (Edge e: resourceDependencyGraph.getEdges()) { + System.out.println(e.getSource() + "->" + e.getDestination()); + } + } + +}