Skip to content

Latest commit

 

History

History

TrainControl

Folders and files

README.md

🚆 Testing a Simple Train Control System Using Its Formal Description

This is a TestFlows example that tests a Ceiling Speed Monitoring Controller (CSMC), the part of a train's control system that warns the driver and applies the emergency brake when the train runs too fast. The test program is built from the controller's formal description and checks all 250 combinations of its input equivalence classes against a Python implementation generated by ChatGPT.

The implementation, train_control_system.py, is kept exactly as ChatGPT generated it, with its two bugs, so that the test program finds them.

👨‍💻 Credits

📚 References

📋 Prerequisites

pip3 install -r requirements.txt

The test program starts the controller with python train_control_system.py, so python must be on your PATH.

🧪 Running the tests

python3 test_train_control_system.py -o slick

The first run fails at combination #3, where the speed limit is 100 km/h and the train reaches 113 km/h:

AssertionError: expected state IS but got WS

The controller checks the speed against the limit before it checks the emergency brake guards, so it warns when it must brake. In the NS state, move the gebi1 or gebi2 check before self.V_est > self.V_MRSP, and run the tests again. They fail at the same combination with the second bug:

AssertionError: expected W=1 but got 0

The controller applies the emergency brake without setting the warning signal. Set self.W to 1 together with self.EB when it moves to the IS state:

        if self.state == "NS":
            if self.V_est <= self.V_MRSP:
                self.state = "NS"  # phi_0
            elif gebi1 or gebi2:
                self.state, self.W, self.EB = "IS", 1, 1  # phi_2
            elif self.V_est > self.V_MRSP:
                self.state, self.W = "WS", 1  # phi_1

With both fixes, all 250 combinations pass.