def test_ensureParserChecksForBracesAndWorksForNoInputs():
    assert serviceUnderTest.parseBarrenFieldInput("{}") == []

    with pytest.raises(FieldParsingException,
                       match="Missing curly brace in input"):
        serviceUnderTest.parseBarrenFieldInput("\"\"}")

    with pytest.raises(FieldParsingException,
                       match="Missing curly brace in input"):
        serviceUnderTest.parseBarrenFieldInput("{\"\"")
示例#2
0
def main():
    """
    Takes in user specified barren land and outputs the area of the reamining
    Land
    """
    # Initalize a new feild with new barren spots
    field = Field(400, 600)

    try:
        # Convert the input into a list of rectangles
        strInput = input("Please input the barren field set: ")
        while '}' not in strInput:
            strInput += input(":")

        barrenFields = parseBarrenFieldInput(strInput)
    except FieldParsingException as e:
        # If there is a parsing error alert the user and exit
        print(str(e))
        return

    # Subract all of the barren feilds from the field
    for barrenField in barrenFields:
        field.removeBarrenArea(barrenField.createContinuosBox())

    # Calculate the area from the remaining feild
    areaList = field.area()

    # Print out the area list in the desired format
    outputString = ""
    for area in areaList:
        outputString += str(int(area)) + " "

    print(outputString.strip())
def test_inputWithVariousWhiteSpacesWorks():
    inputString = "{ \"0 292 399 307\",\"1 50 250 300\"\t,\n \"80 80 80 80\" }"
    expectedOutput = [
        DiscreteRectangle(0, 292, 399, 307),
        DiscreteRectangle(1, 50, 250, 300),
        DiscreteRectangle(80, 80, 80, 80)
    ]
    assert (
        serviceUnderTest.parseBarrenFieldInput(inputString) == expectedOutput)
def test_multipleBoxesEntered_parsesCorrectly():
    inputString = "{\"0 292 399 307\", \"1 50 250 300\", \"80 80 80 80\"}"
    expectedOutput = [
        DiscreteRectangle(0, 292, 399, 307),
        DiscreteRectangle(1, 50, 250, 300),
        DiscreteRectangle(80, 80, 80, 80)
    ]

    assert (
        serviceUnderTest.parseBarrenFieldInput(inputString) == expectedOutput)
示例#5
0
def main():
    field = Field(400, 600)
    strInput = input()
    barrenFields = parseBarrenFieldInput(strInput)

    for barrenField in barrenFields:
        field.removeBarrenArea(barrenField.createContinuosBox())

    areaList = field.area()

    outputString = ""

    for area in areaList:
        outputString += str(int(area)) + " "

    print(outputString.strip())
def test_poorlyFormattedRectangleRaisesAndSaysWhichRectangle():
    with pytest.raises(FieldParsingException,
                       match="Rectangle at position 2 is misformatted"):
        serviceUnderTest.parseBarrenFieldInput(
            "{\"0 292 399 307\", \"1 50 250 300\", \"80 80 80 12 12\"}")
def test_poorlySeperatedSetOfRectanglesRaisesAnException():
    with pytest.raises(FieldParsingException,
                       match="Rectangle set is improperly formatted"):
        serviceUnderTest.parseBarrenFieldInput(
            "{\"0 292 399 307\", blag\"1 50 250 300\", " + "\"80 80 80 80\"}")
def test_oneBoxEntered_parsescorrectly():
    inputString = "{\"0 292 399 307\"}"

    expectedOutput = [DiscreteRectangle(0, 292, 399, 307)]
    assert (
        serviceUnderTest.parseBarrenFieldInput(inputString) == expectedOutput)