Esempio n. 1
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]
Esempio n. 2
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]
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 5
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
Esempio n. 6
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
        def sort_order(self):
            return (hash(self))

    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(tuple([IntThing()]))
    assert result.ok() is True

    result = x.compare_and_resolve_with(tuple([IntThing(), IntThing()]))
    assert result.ok() is False
Esempio n. 7
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]