uchicago-cs / chiventure

A text adventure game engine developed in UChicago's CMSC 22000 - Introduction to Software Development
40 stars 13 forks source link

dsl: write a design document for testing features of the current dsl. #1244

Closed jhsivadas closed 2 years ago

jhsivadas commented 2 years ago

Goal: describe how to write tests for current and future dsl features. Look into potential testing methods for unit tests and larger tests of entire DSL files. Create example test(s) for a current feature of the dsl.

team members: William, Jay, Alex

jhsivadas commented 2 years ago

The testing framework we recommend for testing the DSL features is unittest. Unittest is an extremely flexible framework that supports test automations, aggregation of tests, and test independence. It is structured in an Object-Oriented design to implement this flexibility.

A testing class inherits functions from the unittest library. These functions can be used within the class functions to test differences in direct output. The main tests are:

Unittest also allows subtesting, which can be useful in analyzing iterations

We can use these unittest to check for basic edge cases such as whether or not we have enough objects in one class or not.

## tests whether there is enough items in the room
import unitest
def add_item_to_room(item_list):
    If len(item_list < 3):
        raise ValueError(“Too little item in room please check list”)
    Return {“room”: item_list)

class TestNumItems(unittest.TestCase):
    def item_tracker_success(self):
        actual= add_item_to_room(item_list = [“key, box”])
        expected = {“Room_A” : [“key, box”])
        self.assertEqual(actual, expected)
    def item_tracker_exception(self):
        Items_in_room = [“key, box”, “card”, “coin”]
        With self.asertRaise(ValueError) as exception_context:
            add_item_to_room(items_in_room)
        self.assertEqual(
            str(str(exception_context.exception),
            “Too little item in room please check list”
        )

import unitest
def room_to_dsl(room_list):
    (the function that converts dsl file to wdl format)

class TestRoomList(unittest.TestCase):
    def test_room_to_dsl(self):
        actual= room_to_dsl(list)
        expected = {
            "ROOMS": {
                "room C": {
                        "items": [],
                        "long_desc": "This is a room C. ",
                        "short_desc": "room C"
                    },
                    "room B": {
                        "short_desc": "A dungeon room.",
                        "items": [
                            "Door"
                            ],
                        "long_desc": "This is a room B. "
                        }
                },
            }
        self.assertEqual(actual, expected)

def test_action(action):
    (function that gets actions from Items and returns 
the success text of the action)

Class TestRoomSuccess(unittest.TestCase):
    Def check_text_success(self):
        actual = test_action(action)
        expected ={"action": "OPEN",
                        "text_success": "You open the door."},
                    {"action": "BREAK",
                        "text_success": "You break the door."}
        self.assertEqual(actual, expected)

Notes:
Output if WDL file can be run in Chiventure
See if DSL and WDL input and output are value
Minimal design for 
wzeng0 commented 2 years ago

Jay, Alex, and I researched more into Unittest and what it can offer. For future references, we also created some tests we can possibly use with this library.

jacknugent1529 commented 2 years ago

Issue score: S

Comments: Nice work writing tests! This is certainly something the dsl module needs. remember to convert cards to issue as soon as possible, and in the closing statement try to give a summary of exactly what was accomplished in the issue and why it is now complete.