Monday, 17 April 2023

Chapter 26 // Exercise 4 - Principles & Practice Using C++

In this exercise I'm using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 26 // Exercise 4

Devise a format for test data so that you can define a sequence once and run several tests against it.

I honestly did not understand what he meant by this at first. I guessed that we had defined the test sequence
{ testName value { sequence } testResult }
and so he wants us to be able to define any test sequence like:
{ testName { sequence } value testResult } 
or even
{ testName } { value } { sequence } { testResult }

So in this case I decided to make an enum that held each part of the sequence:

Then, the user could just create a vector<TestSequences> and pass through whatever sequence type they want like:

I then made the functions into a class that held the sequence type, so it could check it whilst using operator>>. I then used a switch statement to define what to do for each part of sequence.

All you have to do then is create a TestSequence, give it a type, set the sequence type and then load in the text file.

It does rely on there being spaces though. Without the spaces, the entire line will be read in however, I imagine that that would be a major "you must do this when writing tests" line in the documentation for creating tests.

No comments:

Post a Comment