Loading...
Hello, my name is Mrs. Holborow, and welcome to Computing.
I'm so pleased you've decided to join me for today's lesson.
Today's lesson is part two of a programming project where you'll apply your knowledge of selection.
In this lesson, we'll focus on testing and refining your programme.
Welcome to today's lesson from the unit Programming sequence.
This lesson is called "Programming project: Selection II," and by the end of today's lesson, you'll be able to implement a solution to a problem that requires the use of selection.
Shall we make a start? We will be exploring these keywords in today's lesson.
Test plan.
Test plan, a document that sets out the tests that will be carried out during testing.
Syntax error.
Syntax error, an error where the code has been structured incorrectly and the syntax rules haven't been followed.
Logic error.
Logic error, an error where the programme will run but won't do what the programmer expected.
Look out for these keywords throughout today's lesson.
Today's lesson is broken down into two sections.
We'll start by testing a programme using a test plan, and then we'll refine a programme by testing.
Let's make a start and test a programme using a test plan.
Testing is the next stage after development in the software development lifecycle.
A test plan is a document that sets out the tests that will be carried out during testing.
Tests should be planned carefully using data that might cause errors as well as data that proves the system works as it should.
A test plan will usually specify the following things.
A unique identifier for each test.
This is so that it can be referred to during test.
It normally starts at one and goes up through the test plan.
So one, two, three, et cetera.
It will also include a description of each test, the test data that will be used for each test, and a description of the expected results of each test.
So here's a blank template table for a test plan.
When final testing, there are three main types of data that can be entered to test your programmes: erroneous, boundary, and normal.
Erroneous data is a type of data that should not be accepted by the programme because doing so would cause an error.
For example, a string is entered when an integer is required.
Boundary.
These are values that are on the edge of being valid.
They should check that values at the boundary are valid and are accepted by your programme.
Normal.
This type of data should be accepted by the programme and is valid.
It is the normal data that you would expect to be entered into your programme.
Time to check your understanding.
What is missing from this test table? Maybe pause the video whilst you have a think.
Did you spot it? That's right, the test ID is missing.
It's useful to give each test a unique test identifier so that it can be referred to during testing.
So for example, test number three failed.
A sandwich shop has the following menu.
So you can see we have sandwich or wrap options and we have various different fillings.
Each have a different price.
The sandwich shop has a couple of special offers, so you can add a drink to any sandwich or wrap for one pound, or you can add crisps to any sandwich or wrap for 30 pence.
The sandwich shop wants an ordering system which allows customers to enter which type of sandwich or wrap they would like, select if they want to add crisps to their order, select if they want to add a drink to their order, and then finally, display the cost of the order.
An example of a test plan for the sandwich ordering system could be as follows.
So you can see here we've used the test plan template, but we've populated it with some tests.
So for test one, we are going to check that a user can select a sandwich as an option.
This is going to be a normal test.
The user is going to enter the word sandwich for the type question.
Our expected results is that the user's input is accepted and the programme moves on to the next question about which filling is required.
For test two, we are going to check that a user cannot enter a string for the filling option.
The filling options are provided from one to six, so this is going to be an erroneous test.
We are going to get the user to enter the word six instead of the number six for the filling question.
Our expected result is that the user's input is not accepted and a data type error message is printed.
For test three, we are going to check that a user can select filling option six.
This is boundary test data because it's on the edge of being valid.
Expected result for this test is that the user's input is accepted because six is an allowed filling option and the programme will move on to the next question.
Time to check your understanding.
Which of the following is the most accurate description of boundary test data? Is it A, this type of data should be accepted by the programme and is valid; B, these are values that are on the edge of being valid; or C, this type of data should not be accepted by the programme? Pause the video whilst you have a think.
Did you select B? Great work.
Boundary test data are values that are on the edge of being valid.
Okay, we've come to our first task of today's lesson and you're doing a great job so far.
So well done.
Open the sandwich ordering system you have created previously.
If you don't have a previous version, don't worry.
You can access a version at oak.
link/sandwich-part-completed.
Carry out these tests and record the actual results.
Pause the video whilst you have a go at the activity.
Did you manage to test the system? Great work.
Here are some sample answers for my test plan, but remember, your sample answers or your test plan may look different from this.
So for test one, the actual result was that the input is accepted and the programme moves on to the next question.
So my actual results matched my predicted or expected results.
Test two.
The actual results were that the user's input is not accepted and that a data type error occurs.
Again, my actual results matched my expected results.
For test three, the actual results look a bit different from my expected results.
So six was not accepted as a filling when I tested it, only fillings one to five were accepted.
So this has identified a bit of a problem in my programme.
Remember, this is just an example test plan, and your test results may be different.
Okay, we are now moving on to the second part of today's lesson where we are going to refine a programme by testing.
Testing allows you to identify errors in a programme.
These may be errors that stop the programme from working completely, like a syntax or runtime error, or an error that means the programme does not work as expected, like a logic error.
Syntax errors.
Programming languages have rules for syntax.
They specify the way that the programme must be written to be understood by a computer.
Programmes written in a programming language must follow the syntax of that language so that it can be understood.
Common syntax errors in Python include things like missing brackets, missing semicolons, and capital letters for keywords like the word print.
Logic errors are errors that cause a programme to work incorrectly or unexpectedly.
With a logic error, the programme can run without failing, but it does not return the expected result.
Logic errors are typically more difficult to detect and find than syntax errors, as the IDE will not be able to pick up the issues or produce clear error messages.
Time to check your understanding.
Fill in the gaps to complete these sentences.
Programmes written in a programming language must follow the of the language so that it can be understood.
Are errors that cause a programme to work incorrectly or unexpectedly.
Pause the video whilst you have a think.
Well done.
Programmes written in a programming language must follow the syntax of that language so that it can be understood.
Logic errors are errors that cause a programme to work incorrectly or unexpectedly.
If you identify errors when testing, then you go back to the development stage and make any refinements that are needed.
Can you spot the four errors in this programme? Maybe pause the video whilst you look carefully at the code.
Did you manage to spot the errors? Let's have a look at them together.
So the first one here is on line four.
We were missing a semicolon at the end of the while.
Next one was on line five.
We're missing a closed bracket for the input message.
On line seven, we were missing a semicolon again, this time on the if statement.
And then finally on line nine, we had else rather than an elif.
So missing colons at the end of selection statements and missing brackets will stop the programme from running.
The else on line nine should have been an elif.
What type of errors are these? Maybe pause the video whilst you have a think.
That's right, you've got it.
They're all syntax errors.
Test three in this test plan shows that choice six is not accepted by the system.
This could be because the selection statement does not include six as an accepted option.
This will need to be refined to make the programme work as expected.
Okay, we are moving on to the last set of tasks for today's lesson, and you've done a fantastic job so far, so well done.
I'd like you to use your test plan to refine your programme.
Don't worry if you don't have access to a programme, you can use the one provided at oak.
link/sandwich-part-completed.
Complete the sandwich ordering system to ensure it works as expected.
And then if you have time, extend the sandwich ordering programme to, A, provide an error message if the user does not select a filling option from one to six for both wraps and sandwiches.
And part B, tell the user they've been awarded a sandwich stamp if their order exceeds four pounds.
Pause the video whilst you have a go at these activities.
How did you get on? Let's have a look at a solution together.
So I'm just showing you line 17 onwards here for the solution because the top part of the programme is just lots of print messages to display the menu to the user.
So on line 17, I'm initiating the total variable to zero.
On line 18, I'm asking the user if they'd like a sandwich or a wrap, and then I'm storing that input as the variable type on line 19.
On line 20, I ask the user what filling they would like from one to six.
And on line 21, I'm storing that as an integer for the variable filling.
On line 23, I go into my first set of selection statements.
So I have if type == "sandwich" and then I have some nested selection statements which go through the filling options.
So if filling == 1, then total is going to be equal to total plus £2.
80.
elif filling == 2, total is going to be equal to total plus £2.
50 and so on.
On line 32, I have an else which then says print("You have not entered a valid filling option") if the user has not entered between the numbers one and six.
So here's the programme continued.
These are the selection statements for the wrap option.
So these look really similar to the ones that we used in the sandwich selection.
We've just changed the prices for the specific filling options.
Here's the final part of the programme.
So on line 49, I'm asking the user if they want crisps with their order.
I'm storing that as input under the variable crisps.
And then I have a selection statement which says if crisps == "y", then the total is going to be equal to total plus 30 pence.
I have a very similar block of code from lines 54 to line 57, which this time ask the user if they want to add a drink to their order.
And then on line 59, I'm printing out the total of the order to the user.
On line 61, I'm checking if the user's total is greater than four, and if it is, I'm printing out the message, "You have earned a sandwich stamp." If you want to go and have a look at the full working solution, you can go to oak.
link/sandwich-solution.
Okay, we've come to the end of today's lesson and you've done a fantastic job, so well done.
Let's summarise what we've learned together.
Testing a programme can help you identify and spot errors.
A test plan is a document that sets out the tests that will be carried out during testing.
Once testing is complete, a programme can be refined to correct any errors and make improvements.
I hope you've enjoyed today's lesson and I hope you'll join me again soon.
Bye.