示例#1
0
def test_configset_getitem():
    """
    Verify that a parameter set and a covering array with
    no "don't care" values present is correctly converted
    to a data frame with the correct column headings and
    value names.
    """
    p1 = Parameter("Colour", [RED, GREEN, BLUE])
    p2 = Parameter("Pet", [BIRD, CAT, DOG])
    p3 = Parameter("Speed", [FAST, MEDIUM, SLOW])
    p4 = Parameter("Music", [SEVENTIES, EIGHTIES, TWENTIES])

    parameter_set = ParameterSet([p1, p2, p3, p4])

    # Covering array from...
    # generator = RecursiveGenerator(parameter_set, 2)
    # covering_array = generator.generate_covering_array()

    covering_array = np.array([[1, 1, 1, 1], [1, 2, 2, 2], [1, 3, 3, 3],
                               [2, 1, 2, 3], [2, 2, 3, 1], [2, 3, 1, 2],
                               [3, 1, 3, 2], [3, 2, 1, 3], [3, 3, 2, 1]])
    configurations = ConfigurationSet(parameter_set=parameter_set,
                                      covering_array=covering_array)

    expected = pd.Series({
        "Colour": GREEN,
        "Pet": BIRD,
        "Speed": MEDIUM,
        "Music": TWENTIES,
    })
    actual = configurations[3]
    assert pd.Series.equals(actual, expected)
示例#2
0
def test_pop_index():
    p = Parameter("Z", [VAL_1, VAL_2, VAL_3, VAL_4])

    popped_val = p.pop(2)

    assert popped_val == VAL_3
    assert p.values == [VAL_1, VAL_2, VAL_4]
示例#3
0
def test_series():
    p = Parameter("Z", [VAL_1, VAL_2])

    s = p.to_series()

    assert s.name == "Z"
    assert s.to_dict() == {0: VAL_1, 1: VAL_2}
示例#4
0
def test_dataframe_to_covering_array():
    p1 = Parameter("Colour", [RED, GREEN])
    p2 = Parameter("Pet", [BIRD, CAT, DOG, FISH])
    p3 = Parameter("Speed", [FAST, SLOW])
    p4 = Parameter("Music", [EIGHTIES, TWENTIES])

    parameter_set = ParameterSet([p1, p2, p3, p4])
    dataframe = pd.DataFrame([
        [RED, BIRD, FAST, EIGHTIES],
        [RED, CAT, SLOW, EIGHTIES],
        [GREEN, BIRD, SLOW, EIGHTIES],
        [GREEN, CAT, FAST, pd.NA],
        [GREEN, CAT, SLOW, TWENTIES],
        [RED, BIRD, FAST, TWENTIES],
        [RED, DOG, FAST, EIGHTIES],
        [GREEN, DOG, SLOW, TWENTIES],
        [RED, FISH, FAST, EIGHTIES],
        [GREEN, FISH, SLOW, TWENTIES],
    ],
                             columns=["Colour", "Pet", "Speed", "Music"])
    covering_array = ConfigurationSet.dataframe_to_covering_array(
        dataframe, parameter_set)
    expected = np.array(
        [[1, 1, 1, 1], [1, 2, 2, 1], [2, 1, 2, 1], [2, 2, 1, 0], [2, 2, 2, 2],
         [1, 1, 1, 2], [1, 3, 1, 1], [2, 3, 2, 2], [1, 4, 1, 1], [2, 4, 2, 2]],
        dtype=DEFAULT_NDARRAY_TYPE)
    assert np.array_equal(covering_array, expected)
示例#5
0
def test_equals():
    """
    Verify that a parameter set and a covering array that
    contains a "don't care" value is correctly converted
    to a data frame, where the "don't care" value becomes
    Pandas' pd.NA value.
    """
    p1 = Parameter("Colour", [RED, GREEN])
    p2 = Parameter("Pet", [BIRD, CAT, DOG, FISH])
    p3 = Parameter("Speed", [FAST, SLOW])
    p4 = Parameter("Music", [EIGHTIES, TWENTIES])

    parameter_set = ParameterSet([p1, p2, p3, p4])

    # Covering array from...
    # generator = RecursiveGenerator(parameter_set, 2)
    # covering_array = generator.generate_covering_array()

    covering_array = np.array([[1, 1, 1, 1], [1, 2, 2, 1], [2, 1, 2, 1],
                               [2, 2, 1, 0], [2, 2, 2, 2], [1, 1, 1, 2],
                               [1, 3, 1, 1], [2, 3, 2, 2], [1, 4, 1, 1],
                               [2, 4, 2, 2]])
    # configs1 = ConfigurationSet(parameter_set, covering_array)
    # configs2 = ConfigurationSet(parameter_set, covering_array)
    configs1 = ConfigurationSet(parameter_set=parameter_set,
                                covering_array=covering_array)
    configs2 = ConfigurationSet(parameter_set=parameter_set,
                                covering_array=covering_array)

    assert configs1 is not configs2
    assert configs1 == configs2
示例#6
0
def test_clear():
    p = Parameter("Z", [VAL_1, VAL_2, VAL_3, VAL_4])

    p.clear()

    assert p.name == "Z"
    assert p.values == []
示例#7
0
def test_dict_round_trip():
    p_orig = Parameter("Z", [VAL_1, VAL_2, VAL_3, VAL_4],
                       uid="337f7234-85a1-45a0-be77-0934ec232f21")

    parameter_dict = p_orig.to_dict()
    p_new = Parameter.from_dict(parameter_dict)

    assert p_new == p_orig
示例#8
0
def test_set_name():
    p = Parameter("Z", [VAL_1, VAL_2, VAL_3, VAL_4])

    p.name = "X"

    p_expected = Parameter("X", [VAL_1, VAL_2, VAL_3, VAL_4], uid=p.uid)

    assert p == p_expected
示例#9
0
def test_create_different_size_parms():
    p1 = Parameter.create_with_unnamed_values("1", 4)
    p2 = Parameter.create_with_unnamed_values("2", 5)
    p3 = Parameter.create_with_unnamed_values("3", 3)
    plist = [p1, p2, p3]

    ps = ParameterSet(plist)

    assert ps.parameters == plist
示例#10
0
def test_to_dict():
    p = Parameter("Z", [VAL_1, VAL_2, VAL_3, VAL_4],
                  uid="337f7234-85a1-45a0-be77-0934ec232f21")
    expected = {
        "name": "Z",
        "uid": "337f7234-85a1-45a0-be77-0934ec232f21",
        "values": [v.to_dict() for v in [VAL_1, VAL_2, VAL_3, VAL_4]],
    }
    assert p.to_dict() == expected
示例#11
0
def test_init_two_parms():
    p1 = Parameter.create_with_unnamed_values("P1", 2)
    p2 = Parameter.create_with_unnamed_values("P2", 3)
    plist = [p1, p2]
    ps = ParameterSet(plist)

    assert len(ps.parameters) == 2
    assert ps.parameters == plist
    assert ps.parameters is not plist  # copy, not reference
示例#12
0
def test_init_three_parms():
    p1 = Parameter.create_with_unnamed_values("P1", 4)
    p2 = Parameter.create_with_unnamed_values("P2", 6)
    p3 = Parameter.create_with_unnamed_values("P3", 2)
    plist = [p1, p2, p3]

    ps = ParameterSet(plist)

    assert len(ps.parameters) == 3
    assert ps.parameters == plist
    assert ps.parameters is not plist  # copy, not reference
示例#13
0
def test_create_same_size_parms():
    ps = ParameterSet.create_from_parm_and_value_sizes(3, 4)

    p1 = Parameter.create_with_unnamed_values("1", 4)
    p2 = Parameter.create_with_unnamed_values("2", 4)
    p3 = Parameter.create_with_unnamed_values("3", 4)
    plist = [p1, p2, p3]
    ps_expected = ParameterSet(plist)

    assert all(
        pactual.name == pexpected.name
        for pactual, pexpected in zip(ps.parameters, ps_expected.parameters))
    assert all(
        len(pactual) == len(pexpected)
        for pactual, pexpected in zip(ps.parameters, ps_expected.parameters))
示例#14
0
def test_init_name_values():
    plist = [VAL_1, VAL_2]

    p = Parameter("Z", plist)

    assert p.name == "Z"
    assert p.values == plist
示例#15
0
def test_init_name_list_str():
    p = Parameter("Z", ["A", "B"])

    assert p.name == "Z"

    v1 = Value("A", uid=p.values[0].uid)
    v2 = Value("B", uid=p.values[1].uid)
    assert p.values == [v1, v2]
示例#16
0
def test_iter():
    p = Parameter("Z", [VAL_1, VAL_2, VAL_3, VAL_4])
    result = []

    for value in p:
        result.append(value)

    assert result == [VAL_1, VAL_2, VAL_3, VAL_4]
示例#17
0
def test_configset_iterate():
    """
    Verify that a parameter set and a covering array with
    no "don't care" values present is correctly converted
    to a data frame with the correct column headings and
    value names.
    """
    p1 = Parameter("Colour", [RED, GREEN])
    p2 = Parameter("Pet", [CAT, DOG])
    p3 = Parameter("Speed", [FAST, SLOW])

    parameter_set = ParameterSet([p1, p2, p3])

    # Covering array from...
    # generator = RecursiveGenerator(parameter_set, 2)
    # covering_array = generator.generate_covering_array()

    covering_array = np.array([[1, 1, 1], [1, 2, 2], [2, 1, 2], [2, 2, 1]])
    configurations = ConfigurationSet(parameter_set=parameter_set,
                                      covering_array=covering_array)

    expected = [
        pd.Series({
            "Colour": RED,
            "Pet": CAT,
            "Speed": FAST,
        }),
        pd.Series({
            "Colour": RED,
            "Pet": DOG,
            "Speed": SLOW,
        }),
        pd.Series({
            "Colour": GREEN,
            "Pet": CAT,
            "Speed": SLOW,
        }),
        pd.Series({
            "Colour": GREEN,
            "Pet": DOG,
            "Speed": FAST,
        })
    ]
    for index, actual in enumerate(configurations):
        assert pd.Series.equals(actual, expected[index])
示例#18
0
def test_from_dict():
    p_dict = {
        "name": "Z",
        "uid": "337f7234-85a1-45a0-be77-0934ec232f21",
        "values": [v.to_dict() for v in [VAL_1, VAL_2, VAL_3, VAL_4]]
    }
    p = Parameter.from_dict(p_dict)
    assert p.name == "Z"
    assert str(p.uid) == "337f7234-85a1-45a0-be77-0934ec232f21"
    assert p.values == [VAL_1, VAL_2, VAL_3, VAL_4]
示例#19
0
def test_init_one_parm():
    p = Parameter.create_with_unnamed_values('Z', 4)

    plist = [
        p,
    ]
    ps = ParameterSet(plist)

    assert ps.parameters == plist
    assert ps.parameters is not plist  # copy, not reference
示例#20
0
def test_generate_configurations_with_dont_care():
    """
    Verify that a parameter set and a covering array that
    contains a "don't care" value is correctly converted
    to a data frame, where the "don't care" value becomes
    Pandas' pd.NA value.
    """
    p1 = Parameter("Colour", [RED, GREEN])
    p2 = Parameter("Pet", [BIRD, CAT, DOG, FISH])
    p3 = Parameter("Speed", [FAST, SLOW])
    p4 = Parameter("Music", [EIGHTIES, TWENTIES])

    parameter_set = ParameterSet([p1, p2, p3, p4])

    # Covering array from...
    # generator = RecursiveGenerator(parameter_set, 2)
    # covering_array = generator.generate_covering_array()

    covering_array = np.array([[1, 1, 1, 1], [1, 2, 2, 1], [2, 1, 2, 1],
                               [2, 2, 1, 0], [2, 2, 2, 2], [1, 1, 1, 2],
                               [1, 3, 1, 1], [2, 3, 2, 2], [1, 4, 1, 1],
                               [2, 4, 2, 2]])
    configurations = ConfigurationSet(parameter_set=parameter_set,
                                      covering_array=covering_array)
    actual_configurations = configurations.configs

    expected_configurations = pd.DataFrame(
        [
            [RED, BIRD, FAST, EIGHTIES],
            [RED, CAT, SLOW, EIGHTIES],
            [GREEN, BIRD, SLOW, EIGHTIES],
            [GREEN, CAT, FAST, pd.NA],
            [GREEN, CAT, SLOW, TWENTIES],
            [RED, BIRD, FAST, TWENTIES],
            [RED, DOG, FAST, EIGHTIES],
            [GREEN, DOG, SLOW, TWENTIES],
            [RED, FISH, FAST, EIGHTIES],
            [GREEN, FISH, SLOW, TWENTIES],
        ],
        columns=["Colour", "Pet", "Speed", "Music"])

    assert actual_configurations.equals(expected_configurations)
示例#21
0
def test_create_with_values():
    p = Parameter.create_with_unnamed_values("Z", 4)

    assert p.name == "Z"

    v1 = Value("1", uid=p.values[0].uid)
    v2 = Value("2", uid=p.values[1].uid)
    v3 = Value("3", uid=p.values[2].uid)
    v4 = Value("4", uid=p.values[3].uid)

    assert p.values == [v1, v2, v3, v4]
示例#22
0
def test_to_dict():
    p1 = Parameter("Colour", [RED, GREEN])
    p2 = Parameter("Pet", [CAT, DOG])
    p3 = Parameter("Speed", [FAST, SLOW])

    parameter_set = ParameterSet([p1, p2, p3])

    # Covering array from...
    # generator = RecursiveGenerator(parameter_set, 2)
    # covering_array = generator.generate_covering_array()

    covering_array = np.array([[1, 1, 1], [1, 2, 2], [2, 1, 2], [2, 2, 1]])
    configurations = ConfigurationSet(parameter_set=parameter_set,
                                      covering_array=covering_array)

    expected = {
        "configurations": [
            {
                "Colour": "Red",
                "Pet": "Cat",
                "Speed": "Fast"
            },
            {
                "Colour": "Red",
                "Pet": "Dog",
                "Speed": "Slow"
            },
            {
                "Colour": "Green",
                "Pet": "Cat",
                "Speed": "Slow"
            },
            {
                "Colour": "Green",
                "Pet": "Dog",
                "Speed": "Fast"
            },
        ]
    }
    actual = configurations.to_dict()
    assert actual == expected
示例#23
0
def test_generate_configurations():
    """
    Verify that a parameter set and a covering array with
    no "don't care" values present is correctly converted
    to a data frame with the correct column headings and
    value names.
    """
    p1 = Parameter("Colour", [RED, GREEN, BLUE])
    p2 = Parameter("Pet", [BIRD, CAT, DOG])
    p3 = Parameter("Speed", [FAST, MEDIUM, SLOW])
    p4 = Parameter("Music", [SEVENTIES, EIGHTIES, TWENTIES])

    parameter_set = ParameterSet([p1, p2, p3, p4])

    # Covering array from...
    # generator = RecursiveGenerator(parameter_set, 2)
    # covering_array = generator.generate_covering_array()

    covering_array = np.array([[1, 1, 1, 1], [1, 2, 2, 2], [1, 3, 3, 3],
                               [2, 1, 2, 3], [2, 2, 3, 1], [2, 3, 1, 2],
                               [3, 1, 3, 2], [3, 2, 1, 3], [3, 3, 2, 1]])
    configurations = ConfigurationSet(parameter_set=parameter_set,
                                      covering_array=covering_array)
    actual_configurations = configurations.configs

    expected_configurations = pd.DataFrame(
        [
            [RED, BIRD, FAST, SEVENTIES],
            [RED, CAT, MEDIUM, EIGHTIES],
            [RED, DOG, SLOW, TWENTIES],
            [GREEN, BIRD, MEDIUM, TWENTIES],
            [GREEN, CAT, SLOW, SEVENTIES],
            [GREEN, DOG, FAST, EIGHTIES],
            [BLUE, BIRD, SLOW, EIGHTIES],
            [BLUE, CAT, FAST, TWENTIES],
            [BLUE, DOG, MEDIUM, SEVENTIES],
        ],
        columns=["Colour", "Pet", "Speed", "Music"])

    assert actual_configurations.equals(expected_configurations)
示例#24
0
def pet(orm, bird, cat, dog):
    return Parameter("Pet", values=[bird, cat, dog])
示例#25
0
def colour(orm, red, green, blue):
    return Parameter("Colour", values=[red, green, blue])
示例#26
0
def parm_2():
    return Parameter.create_with_unnamed_values("2", 3)
示例#27
0
def parm_d(d1, d2, d3, d4):
    return Parameter("D", [d1, d2, d3, d4])
示例#28
0
def speed(orm, fast, medium, slow):
    return Parameter("Speed", values=[fast, medium, slow])
示例#29
0
def music(orm, seventies, eighties, twenties):
    return Parameter("Music", values=[seventies, eighties, twenties])
示例#30
0
def parm_e(a1, e1, e2):
    return Parameter("E", [e1, e2])