예제 #1
0
파일: main.cpp 프로젝트: gatesyp/coursework
void test_copies()
{
    // Test for range of integers
    std::vector<int> val_1 = {12,2,3,4,5,1,6,7,8,9,10};
    std::vector<int> val_2(11);
    auto it = copies(val_1.begin(),val_1.end(),val_2.begin());
    assert(*(val_1.begin())==*(val_2.begin()));
    assert(it == val_2.end());

    // Test for range of Strings
    std::vector<std::string> str_1={"Hi", "this", "is", "a", "test", "for", "equal"};
    std::vector<std::string> str_2(7);
    auto StrIterator = copies(str_1.begin(),str_1.end(),str_2.begin());
}
예제 #2
0
파일: w.cpp 프로젝트: fons/functional-cpp
int w_1()
{
  W id(0,"");
  W val_1(1256, "hello");
  W val_2(-9088, "goodbye");
  W val_3(786, "haha");

  if ((id + val_1) == (val_1 + id)) {
    std::cout << "have indentity element" << std::endl;
  }
  
  if ((val_3 + (val_2 + val_1)) == ((val_3 + val_2) + val_1)) {
    std::cout << "have associativity" << std::endl;
  }
  
  return 0;
}
예제 #3
0
static void _testInstances(void)
{
    // Simple test: instance with a few string properties
    {
        WsmInstance inst("testClass");
        WsmValue val_1("value_1");
        WsmValue val_2("value_2");
        inst.addProperty(WsmProperty("property_1", val_1));
        inst.addProperty(WsmProperty("property_2", val_2));

        _checkInstance(inst,
            "Instances with string properties do not compare");
    }

    // Test string array properties
    {
        WsmInstance inst("testClass");
        Array<String> stra;
        for (int i = 0; i < 5; i++)
        {
            char buf[20];
            sprintf(buf, "prop_1 value: %d", i);
            stra.append(buf);
        }
        WsmValue val1(stra);
        inst.addProperty(WsmProperty("property_1", val1));

        stra.clear();
        for (int i = 0; i < 10; i++)
        {
            char buf[20];
            sprintf(buf, "prop_2 value: %d", i);
            stra.append(buf);
        }
        WsmValue val2(stra);
        inst.addProperty(WsmProperty("property_2", val2));

        _checkInstance(inst,
            "Instances with string array properties do not compare");
    }

    // Test EPR properties
    {
        WsmInstance inst("testClass");
        WsmEndpointReference epr;
        epr.address = "http://www.acme.com:5988/wsman";
        epr.resourceUri = "TestURI";
        epr.selectorSet->selectors.
            append(WsmSelector("sel_1 name", "sel_1 value"));
        epr.selectorSet->selectors.
            append(WsmSelector("sel_2 name", "sel_2 value"));
        WsmValue val(epr);
        inst.addProperty(WsmProperty("property_1", val));

        _checkInstance(inst, "Instances with EPR properties do not compare");
    }

    // Test EPR array properties
    {
        WsmInstance inst("testClass");
        Array<WsmEndpointReference> epra;
        for (int i = 0; i < 5; i++)
        {
            char buf[50];
            WsmEndpointReference epr;
            sprintf(buf, "http://www.acme.com_%d:5988/wsman", i);
            epr.address = buf;
            sprintf(buf, "TestURI_%d", i);
            epr.resourceUri = buf;
            sprintf(buf, "selector value %d", i);
            epr.selectorSet->selectors.
                append(WsmSelector("sel_name", buf));
            epra.append(epr);

        }
        WsmValue val(epra);
        inst.addProperty(WsmProperty("property_1", val));

        _checkInstance(inst,
            "Instances with EPR array properties do not compare");
    }

    // Test recursive EPR properties
    {
        WsmInstance inst("testClass");

        WsmEndpointReference epr1;
        epr1.address = "http://www.acme.com_1:5988/wsman";
        epr1.resourceUri = "TestURI_1";
        epr1.selectorSet->selectors.
            append(WsmSelector("sel_0 name", "sel_1 value"));
        epr1.selectorSet->selectors.
            append(WsmSelector("sel_1 name", "sel_2 value"));

        WsmEndpointReference epr2;
        epr2.address = "http://www.acme.com_2:5988/wsman";
        epr2.resourceUri = "TestURI_2";
        epr2.selectorSet->selectors.append(WsmSelector("sel_2 name", epr1));

        WsmEndpointReference epr3;
        epr3.address = "http://www.acme.com_3:5988/wsman";
        epr3.resourceUri = "TestURI_3";
        epr3.selectorSet->selectors.append(WsmSelector("sel_3 name", epr2));

        WsmEndpointReference epr;
        epr.address = "http://www.acme.com:5988/wsman";
        epr.resourceUri = "TestURI";
        epr.selectorSet->selectors.append(WsmSelector("sel name", epr3));

        WsmValue val(epr);
        inst.addProperty(WsmProperty("property_1", val));

        _checkInstance(inst,
            "Instances with recursive EPR properties do not compare");
    }

    // Test embedded instance properties
    {
        WsmInstance inst1("testClass_1");
        WsmValue val_1("value_1");
        WsmValue val_2("value_2");
        inst1.addProperty(WsmProperty("property_1", val_1));
        inst1.addProperty(WsmProperty("property_2", val_2));

        WsmInstance inst("testClass");
        WsmValue val_3(inst1);
        inst.addProperty(WsmProperty("property_3", val_3));

        _checkInstance(inst,
            "Instances with instance properties do not compare");
    }

    // Test arrays of embedded instances
    {
        WsmInstance inst("testClass");
        Array<WsmInstance> insta;
        for (int i = 0; i < 5; i++)
        {
            char buf[20];
            sprintf(buf, "testClass_%d", i);
            WsmInstance inst1(buf);
            sprintf(buf, "value_%d", i);
            WsmValue val(buf);
            sprintf(buf, "property_%d", i);
            inst1.addProperty(WsmProperty(buf, val));

            insta.append(inst1);
        }
        WsmValue val(insta);
        inst.addProperty(WsmProperty("prop_array", val));

        _checkInstance(inst,
            "Instances with instance array properties do not compare");
    }

    // Test recursive embedded instances
    {
        WsmInstance inst1("testClass_1");
        WsmValue val_0("value_0");
        WsmValue val_1("value_1");
        inst1.addProperty(WsmProperty("property_0", val_0));
        inst1.addProperty(WsmProperty("property_1", val_1));

        WsmInstance inst2("testClass_2");
        WsmValue val_2(inst1);
        inst2.addProperty(WsmProperty("property_2", val_2));

        WsmInstance inst3("testClass_3");
        WsmValue val_3(inst2);
        inst3.addProperty(WsmProperty("property_3", val_3));

        WsmInstance inst("testClass");
        WsmValue val(inst3);
        inst.addProperty(WsmProperty("property", val));

        _checkInstance(inst,
            "Instances with recursive instance properties do not compare");
    }
}