# Author: Scott Wehrwein
# Date: 11/12/2025
# A program to demonstrate testing basics, including pytest mechanics,
# input space partitioning, and boundary value analysis.

import pytest
from gradecalc import letter_grade

"""
For reference, here's the spec for the function we're testing:
"""
# def letter_grade(score):
#     """ Calculate the letter grade corresponding to the given score.
#     Precondition: score is a float between 0 and 100 (inclusive).
#     Returns a letter grade as a string according to the usual ranges:
#         F for scores less than 60
#         D for scores from 60 (inclusive) up to 70 (exclusive)
#         C for scores from 70 (inclusive) up to 80 (exclusive)
#         B for scores from 80 (inclusive) up to 90 (exclusive)
#         A for scores 90 or above
#     """

"""
0. Partition the input space into regions where the program will behave the same:

 0 <= score < 60 |  60 <= score < 70 |  70 <= score < 80 |  80 <= score < 90 | 90 <= score
     (F)                   (D)                   (C)                   (B)           (A)
     

1. Write tests that check the behavior inside each of these regions.

2. Write tests that check the behavior right near the boundaries of these regions.

"""
# pytest assumes that methods starting with test_ are test cases
def test_partitions():
    """ Test values in the "middle" of the input space partitions """
    assert letter_grade(30.0) == "F"
    assert letter_grade(65.0) == "D"
    assert letter_grade(75.0) == "C"
    assert letter_grade(85.0) == "B"
    assert letter_grade(95.0) == "A"

def test_boundaries():
    """ Test values on either side of the boundaries """
    assert letter_grade(59.9999) == "F"
    assert letter_grade(60.0) == "D"
    # and so on for the boundaries around 70, 80, and 90

if __name__ == "__main__":
    # run pytest with the test functions in this program
    pytest.main(["gradecalc_test.py", "-vv", "-p", "no:faulthandler"])
