Ejemplo n.º 1
0
def test_subsets_simple_1(caplog):
    caplog.set_level(logging.DEBUG)
    c = Constants(matriculation_year=2000)

    x = load_clause({"attributes": {"$eq": "electives"}}, c=c)
    y = load_clause({"attributes": {"$eq": "doggie"}}, c=c)
    assert x.is_subset(y) is False
Ejemplo n.º 2
0
def test_subsets_simple_4(caplog):
    caplog.set_level(logging.DEBUG)
    c = Constants(matriculation_year=2000)

    x = load_clause({"$and": [{"attributes": {"$in": ["electives"]}}]}, c=c)
    y = load_clause({"attributes": {"$eq": "electives"}}, c=c)
    assert x.is_subset(y) is False
    assert y.is_subset(x) is True
Ejemplo n.º 3
0
def test_ranges_lte(caplog):
    caplog.set_level(logging.DEBUG)
    c = Constants(matriculation_year=2000)

    x = load_clause({"count(courses)": {"$lte": 5}}, c=c)
    result = x.input_size_range(maximum=7)
    assert list(result) == [0, 1, 2, 3, 4, 5]
Ejemplo n.º 4
0
def test_ranges_gte_at_most(caplog):
    caplog.set_level(logging.DEBUG)
    c = Constants(matriculation_year=2000)

    x = load_clause({"count(courses)": {"$gte": 1, "at_most": True}}, c=c)
    result = x.input_size_range(maximum=5)
    assert list(result) == [1]
Ejemplo n.º 5
0
def test_clause__grade_code():
    c = Constants(matriculation_year=2000)

    clause = load_clause({"grade_code": {"$in": ["P", "IP", "S"]}}, c=c)

    y_course = course_from_str(s="CSCI 296", grade_code="P")
    n_course = course_from_str(s="CSCI 296", grade_code="F")

    assert clause.apply(y_course) is True
    assert clause.apply(n_course) is False
Ejemplo n.º 6
0
def test_clauses(caplog):
    caplog.set_level(logging.DEBUG)

    c = Constants(matriculation_year=2000)

    x = load_clause({"attributes": {"$eq": "csci_elective"}}, c=c)
    expected_single = SingleClause(key="attributes", expected="csci_elective", expected_verbatim="csci_elective", operator=Operator.EqualTo)
    assert x == expected_single

    crs = course_from_str(s="CSCI 121", attributes=["csci_elective"])

    assert x.apply(crs) is True
Ejemplo n.º 7
0
def test_clauses_in(caplog):
    caplog.set_level(logging.DEBUG)

    c = Constants(matriculation_year=2000)
    course = course_from_str(s="CSCI 296")

    values = tuple([296, 298, 396, 398])
    x = load_clause({"number": {"$in": values}}, c=c)
    expected_single = SingleClause(key="number", expected=values, expected_verbatim=values, operator=Operator.In)
    assert x == expected_single

    assert x.apply(course) is True
Ejemplo n.º 8
0
def test_resolution(caplog):
    caplog.set_level(logging.DEBUG)

    c = Constants(matriculation_year=2000)

    class IntThing(Clausable):
        def apply_single_clause(self):
            pass
        def to_dict(self):
            pass

    x = load_clause({"count(items)": {"$eq": 1}}, c=c)
    expected_single = SingleClause(key="count(items)", expected=1, expected_verbatim=1, operator=Operator.EqualTo)
    assert x == expected_single

    result = x.compare_and_resolve_with([IntThing()])
    assert result.ok() is True

    result = x.compare_and_resolve_with([IntThing(), IntThing()])
    assert result.ok() is False
Ejemplo n.º 9
0
def test_ranges_eq_2(caplog):
    """ensure that a solution with fewer matching courses than requested is still proposed"""
    caplog.set_level(logging.DEBUG)
    c = Constants(matriculation_year=2000)

    result = load_clause({"count(courses)": {"$eq": 3}}, c=c).input_size_range(maximum=2)
    assert list(result) == [2]

    result = load_clause({"count(courses)": {"$neq": 3}}, c=c).input_size_range(maximum=2)
    assert list(result) == [0, 1, 2]

    result = load_clause({"count(courses)": {"$lt": 3}}, c=c).input_size_range(maximum=2)
    assert list(result) == [0, 1, 2]

    result = load_clause({"count(courses)": {"$lte": 3}}, c=c).input_size_range(maximum=2)
    assert list(result) == [0, 1, 2, 3]

    result = load_clause({"count(courses)": {"$gt": 3}}, c=c).input_size_range(maximum=2)
    assert list(result) == [2]

    result = load_clause({"count(courses)": {"$gte": 3}}, c=c).input_size_range(maximum=2)
    assert list(result) == [2]