Test Cases and Code Review for Order and Hotel Reservation Validation

Computer science3.05 KB

Validation Test Cases

Variables, Rules, Valid and Invalid Classes

Variable / Rule / Valid Class / Invalid Class

order_id / Datatype / ECV1: 32 hex string / ECNV1: not a string

order_id / Content: hexadecimal characters / ECV2: 32 hex string / ECNV2: 32 characters, non-hex

order_id / Size = 32 characters / ECV3: 32 hex string; BVV1: 32 hex string / ECNV3: more than 32 characters; ECNV4: less than 32 characters; BVNV1: 33 hex characters; BVNV2: 31 hex characters

new_order_type / Datatype / ECV4: valid value / ECNV5: datatype not string

new_order_type / Allowed values / ECV5: "REG"; ECV6: "PREM" / ECNV6: other value

- / Outputs / ECV7: valid phone number / ECNV7: Ex: InvalidOrder_idSize; ECNV8: Ex: order_idNotStr; ECNV9: Ex: ord_idNotHexVal; ECNV10: alreadySent; ECNV11: notFound; ECNV12: invalidOrdrType

Test Case Table

ID / order_id / new_order_type / Expected result / EC / BV tested

1 / "32hexchars" / "REG" / valid phone number / ECV1, ECV2, ECV3, ECV4, ECV5, ECV7, BVV1

2 / "32hexchars" / "PREM" / valid phone number / ECV6

3 / 212213... (int) / "REG" / Ex / ECNV1, ECNV8

4 / "HOL34..." (32 chars) / "REG" / Ex / ECNV2, ECNV9

5 / "33hexchar" / "REG" / Ex / ECNV3, ECNV7, BVNV1

6 / "31hexchar" / "REG" / Ex / ECNV4, BVNV2

7 / "32hexchars" / "OTRO" / Ex / ECNV6, ECNV12

8 / "32hexchars" / 12345 / Ex / ECNV5

9 / valid 32 hex, not registered / "REG" / Ex / ECNV11

10 / valid 32 hex, already sent / "REG" / Ex / ECNV10

Cyclomatic Complexity

V(G) = E - N + 2P

Test Cases for the Key-Value Filter

Case / _data_list (initial) / key, value / Expected result

1 / [] / "id", "1" / []

2 / [{"id":"1"}] / "id", "2" / [{"id":"1"}]

3 / [{"id":"1"}] / "id", "1" / []

4 / [{"id":"1"},{"id":"2"}] / "id", "1" / [{"id":"2"}]

Code Review: HotelManager

Current Implementation

The method update_room_reservation_type validates the localizer and room type, retrieves the reservation, sets the private attribute _HotelReservation__room_type directly, removes the previous version from the store, and saves the updated reservation. Any exception is wrapped in HotelManagementException.

Recommendation

Add a method to the HotelReservation class to encapsulate the update logic instead of modifying the private attribute from outside:

class HotelReservation:
    def update_room_type(self, new_room_type: str):
        self.__room_type = RoomType(new_room_type).value

Then call it from HotelManager:

reservation.update_room_type(room_type)

This improves encapsulation, keeps validation within the domain class, and makes HotelManager easier to maintain and test.

Download

PDF Word HTML