{"id":160,"date":"2024-07-30T06:50:31","date_gmt":"2024-07-30T06:50:31","guid":{"rendered":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/chapter\/testing-patterns\/"},"modified":"2026-03-16T14:30:54","modified_gmt":"2026-03-16T14:30:54","slug":"testing-patterns","status":"publish","type":"chapter","link":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/chapter\/testing-patterns\/","title":{"raw":"Testing Patterns","rendered":"Testing Patterns"},"content":{"raw":"<div class=\"testing-patterns\">\n<p class=\"import-Normal\">Now that we've explored the how-tos and whys, let's take a look at how to determine what to test and how to know if it's tested well enough. Remember, the ultimate goal of testing is to reach complete code coverage. Your tests should test every line of code at least once. However, you still need to consider the possible scenarios to ensure that you've written enough code! In this section, we'll look at some common scenarios that could be tested.<\/p>\n\n<h3>User Input<\/h3>\n<p class=\"import-Normal\">For programs that take input from the user, the input that the user provides is a perfect source of errors. You can never trust the user! In these cases, you'll want to test<\/p>\n\n<ul>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">valid input<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">invalid input\n<ul>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">which may include input that is out of range, the wrong type (like inputting letters instead of numbers), or unusable data<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p class=\"import-Normal\">Your program should work correctly with valid input. That's a given. For invalid input, however, you need to decide if it makes sense for your program to handle the invalid input. For example, if your program has a menu, it makes sense to be able to recover if the user enters an invalid menu choice. Just let the user try again. On the other hand, if your program is supposed to perform some mathematical computation and the user enters characters, you have to decide if it makes sense to let the user try again or just let the program fail. What you don't want to do is just push the error down the line; if the user gives you invalid input, your program should immediately handle it and get corrected input or it should fail LOUDLY. A bug based on an exception is much easier to find than a bug where your output is just wrong for some reason.<\/p>\n\n<h3>Classes<\/h3>\n<p class=\"import-Normal\">When testing a class, you should have at least one test per public method. As discussed earlier, since you can't directly test private methods, their correctness has to be assessed indirectly. The tests you need to run depend on the method, but the considerations are similar to testing users' input. Here are some general things to consider.<\/p>\n\n<h4>Constructors<\/h4>\n<p class=\"import-Normal\">The purpose of a [pb_glossary id=\"226\"]<strong>constructor <\/strong>[\/pb_glossary]is to initialize the <strong>[pb_glossary id=\"227\"]instance variables[\/pb_glossary] <\/strong>and get the object ready to use. You should test that the instance variables are set correctly and any other set up has been properly done. This often involves using the getters (accessors).<\/p>\n\n<h4>Getters and Setters<\/h4>\n<p class=\"import-Normal\">[pb_glossary id=\"228\"]<strong>Getters <\/strong>[\/pb_glossary]and [pb_glossary id=\"229\"]<strong>setters<\/strong>[\/pb_glossary], also known as <strong>accessors <\/strong>and <strong>mutators<\/strong>, are how other classes access and manipulate the values of the instance variables in a properly encapsulated class. The getters are often used as part of testing the constructors, so you don't necessarily need specific tests for the getters. It is not wrong, however, to include such tests. Setters should be tested to ensure they properly update the variables, especially if the setter validates the new value. For example, if you have a method like <em>setAge<\/em> that verifies that the new age is positive, you'll want to ensure that the age is only changed if the new value is valid. Setters are usually tested with the help of getters.<\/p>\n\n<div class=\"textbox textbox--exercises\"><header class=\"textbox__header\"><strong>Test Yourself<\/strong><\/header>\n<div class=\"textbox__content\">\n<ul>\n \t<li>What tests would you want to run on the <em>setAge<\/em> method described above?<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<h4>toString<\/h4>\n<p class=\"import-Normal\">This is another method that can be used to test other methods, depending on what's used to create the String representation. Since the String representation of an object usually involves at least some of the instance variables, it can be a quick way to verify that changes have taken effect. For example, if you have a <em>List <\/em>class that represents a list and <em>toString<\/em> includes a print out of all of the elements, it can be a quick way to verify that the elements in the list are correct and in the correct order. It is worth testing <em>toString<\/em> on its own so that if its own test passes but another test using <em>toString<\/em> doesn't, you can rule out the bug being in <em>toString<\/em>.<\/p>\n<p class=\"import-Normal\">You generally want to verify that <em>toString<\/em> is correct on a newly created object and after the object has been modified in such a way that the String representation would have changed.<\/p>\n\n<h4>Equality and Comparisons<\/h4>\n<p class=\"import-Normal\">While classes you write should always have constructors, getters and\/or setters, and a <em>toString<\/em>, your class may or may not have methods such as <em>equals, compareTo, <\/em>or <em>compare.<\/em> If your class does have these methods, you need to test them thoroughly! These are good examples of methods where you need to consider the scenarios in which these methods will be used. Those scenarios will help guide what tests you need to write.<\/p>\n<p class=\"import-Normal\">Consider the method <em>equals.<\/em> There are two possible outcomes of this method: the other object is equal to this object or the other object is not equal to this object. Each of these scenarios should be tested separately (i.e. in different test methods). Don't stop there, though! If your <em>equals<\/em> method determines equality based on different instance variables, you should test that objects are or are not equal with varying combinations of equality amongst the instance variables. For example, suppose you have a <em>Dog<\/em> class that represents a dog and one Dog object is equal to another if and only if both Dogs have the same name and age. This means that a dog named Fido who is 7 years old would <em>not <\/em>be equal to a dog named Fido who is 3 years old. For an <em>equals<\/em> method like this, you would have the following tests:<\/p>\n\n<ul>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">equal objects where the names and ages are exactly the same<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">unequal objects where the names are different and the ages are different<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">unequal objects where the names are the same, but the ages are different<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">unequal objects where the ages are the same, but the names are different<\/li>\n<\/ul>\n<p class=\"import-Normal\">Similar considerations are required for methods like <em>compareTo.<\/em> A <em>compareTo<\/em> method should return the relative ordering between this object and the parameter object. It returns something negative if this object is less than the parameter, something positive if this object is greater than the parameter, and 0 if this object and the parameter are equal. Note that if <em>equals<\/em> considers objects equal, <em>compareTo<\/em> should also consider the objects equal.<\/p>\n\n<div class=\"textbox textbox--exercises\"><header class=\"textbox__header\">\n<p class=\"textbox__title\"><strong>Test Yourself<\/strong><\/p>\n\n<\/header>\n<div class=\"textbox__content\">\n<ul>\n \t<li class=\"import-Normal\">What are the three scenarios for compareTo?<\/li>\n \t<li class=\"import-Normal\">Given the Dog class, Dogs are ordered first by age, then by name. What should be returned when comparing Fido, age 3, and Spot, age 5?<\/li>\n \t<li class=\"import-Normal\">What is the minimum number of test methods you would need to fully test this compareTo?<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<h3>Loops<\/h3>\n<p class=\"import-Normal\">While you generally won't just test a loop, these cases can help you determine how to test a method or program that contains a loop. The most common bugs with loops occur with respect to the stopping condition; <strong>off by one errors<\/strong> are quite common. These occur when <strong>boundary cases<\/strong> are not handled correctly. For example, if you have a loop that is supposed to run while the value of <em>i<\/em> is less than 10, 10 is the boundary condition because that's the value that's on the border of looping and not looping. You'd want to check that 9 loops but 10 does not. If 10 does loop but 11 doesn't, that would be an off by one error. The basic values to consider when testing a loop are as follows.<\/p>\n\n<ul>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">the initial condition\n<ul>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">does the loop start on or with the correct condition<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">if it needs to, does the code do the right thing if the loop never runs?<\/li>\n<\/ul>\n<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">end condition\n<ul>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">does the loop stop correctly? Check the boundary cases and off-by one cases.<\/li>\n<\/ul>\n<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">side effects of the loop\n<ul>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">did the loop accomplish what it was supposed to do?<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<div class=\"textbox textbox--exercises\"><header class=\"textbox__header\">\n<p class=\"textbox__title\"><strong>Test Yourself\n<\/strong><\/p>\n\n<\/header>\n<div class=\"textbox__content\">\n<ul>\n \t<li class=\"import-Normal\">Suppose you have a loop that sums the values from <em>min<\/em> to <em>max<\/em>. What test cases might you use?<\/li>\n \t<li class=\"import-Normal\">Suppose you have a loop that prints the elements of an array from the second element to the second to last element. What behavior do you expect from this loop?<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<h3>Lists<\/h3>\n<p class=\"import-Normal\">At some point in this class, you will write your own list. If you\u2019re not there yet, feel free to come back to this section when you are ready to start writing tests for your lists.<\/p>\n<p class=\"import-Normal\">A [pb_glossary id=\"230\"]<strong>list <\/strong>[\/pb_glossary]is a way to organize, store, and access data. To test your list, you must first determine how the user will be able to interact with the list. Does the user have [pb_glossary id=\"231\"]<strong>random access<\/strong> [\/pb_glossary]to the elements? Can the user add or remove from the list? Can the user update elements? Be sure that you understand the mental model of your list before you being writing tests.<\/p>\n<p class=\"import-Normal\">Like testing a class, you will want to write tests for each public method. The tricky part about testing list methods is that you need to consider the state of the list and how that changes the behavior of the method. Here are some general guidelines.<\/p>\n<p class=\"import-Normal\">First, you should consider the state of the list. There are three basic states: the list is empty, the list has one or two items, and the list has three or more items. A list with three elements is the smallest list that has a first, middle, and last element. For testing purposes, we consider three elements to be a sufficiently full list <em>unless you need to test a structure that can become \u201cfull\u201d (like an array list).<\/em> If your list can become full, you need to test that it behaves correctly when it\u2019s full.<\/p>\n<p class=\"import-Normal\">Second, you should consider the location of the element. Again, there are three basic locations: the front, the middle, and the end. We consider all middle elements equally in the middle; that is, a middle element in a three element list should behave the same as a middle element in a ten element list. Both middle elements have an element on either side of it, so theoretically if your method works for one middle element, it ought to work for all middle elements.<\/p>\n<p class=\"import-Normal\">Let\u2019s look at a few examples. For these examples, we will assume we have an unordered, linear list with random access, e.g. a list. We will not assume any particular implementation. Lists will be represented using square brackets. An empty list looks like this: [ ]. A list containing a single element, A, looks like this: [ A ]. A list containing the elements A and B in that order looks like this: [ A, B ].<\/p>\n<p class=\"import-Normal\">Furthermore, when we discuss possible list scenarios in this class, we will use the following format:<\/p>\n<p class=\"import-Normal\" style=\"text-indent: 36pt\">Starting list \ud83e\udc6a Resulting list<\/p>\n<p class=\"import-Normal\">Thus, the scenario that we start with a list containing the element B and end up with a list containing B and C (in that order) would be represented as:<\/p>\n<p class=\"import-Normal\">[ B] \ud83e\udc6a [ B, C ].<\/p>\n\n<h4>Add Method<\/h4>\n<p class=\"import-Normal\">When you add to a list, you expect that the element you add ends up in the list. Let\u2019s assume that this add method adds the new element to the end of the list. Now we need to consider the possible scenarios. In how many ways could we add to a list?<\/p>\n<p class=\"import-Normal\">Considering the possible states of the list, we could add to an empty list. We could add to a list that has one element. We could add to a list that has two elements. We could add to a list that has three elements. A list with four or more elements should behave the same as a list with three elements.<\/p>\n\n<div class=\"textbox textbox--exercises\"><header class=\"textbox__header\">\n<p class=\"textbox__title\"><strong>Test Yourself<\/strong><\/p>\n\n<\/header>\n<ul>\n \t<li class=\"import-Normal\">Suppose you have an empty list, represented as [ ]. If you add element A to the list, what would you expect the resulting list to look like?<\/li>\n \t<li class=\"import-Normal\">Suppose you have a list with one element, represented as [ A ]. If you add element B to the list, what would you expect the resulting list to look like?<\/li>\n<\/ul>\n<\/div>\n<p class=\"import-Normal\">Next, consider the location of the element. The element could be in the first, middle, or last position. Remember that in this method, the element is always added to the end of the list.<\/p>\n\n<div class=\"textbox textbox--exercises\"><header class=\"textbox__header\"><strong>Test Yourself<\/strong><\/header>\n<div class=\"textbox__content\">\n<ul>\n \t<li class=\"import-Normal\">In what starting list(s) would adding a new element, A, result in the new element being the first element?<\/li>\n \t<li class=\"import-Normal\">In what starting list(s) would adding a new element, A, result in the new element being the middle element?<\/li>\n \t<li class=\"import-Normal\">In what starting list(s) would adding a new element, A, result in the new element being the last element?<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<p class=\"import-Normal\">How does all of this translate to test cases? We\u2019ve demonstrated that we really only have four possible scenarios: adding to an empty list, adding to a list with one element, adding to a list with two elements, and adding to a list with three elements. Adding to an empty list covers two scenarios: the list is empty and the newly added element is the first element. Adding to a one element list also covers two scenarios: the list has one element and the newly added element is the last element. The other scenarios are covered by adding to a list with two elements and adding to a list with three elements. For this method, it is impossible to add to the list and end up with the new element in the middle, so we don\u2019t need to worry about that scenario.<\/p>\n\n<div class=\"textbox textbox--exercises\"><header class=\"textbox__header\">\n<p class=\"textbox__title\"><strong>Test Yourself<\/strong><\/p>\n\n<\/header>\n<div class=\"textbox__content\">\n<ul>\n \t<li class=\"import-Normal\">What is the minimum number of test cases you would need to write to test this add method?<\/li>\n \t<li class=\"import-Normal\">List the scenarios that represent the test cases that should be written.\u00a0 Assume that the next unique letter will be added to the list (e.g. if the list already contains A, the next element added would be B. If the list already contains A and B, the next element added would be C, etc)<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<p class=\"import-Normal\">Now, we\u2019ve always assumed that we are adding unique elements. In a general list and in this particular method, duplicate items shouldn\u2019t cause a problem. However, it is good to keep in mind whether it matters if duplicate items exist and if they could cause problems. If it does matter, then adding a test that tests duplicated items is prudent!<\/p>\n\n<h4>Get Method<\/h4>\n<p class=\"import-Normal\">There are a number of different ways to get elements out of a list, depending on whether the list restricts access (like a [pb_glossary id=\"232\"]<strong>queue<\/strong>[\/pb_glossary]), if the elements have a unique index (like an [pb_glossary id=\"233\"]<strong>array<\/strong>[\/pb_glossary]), or if the elements are even expected to be in a particular order (like an unordered [pb_glossary id=\"234\"]<strong>set<\/strong>[\/pb_glossary]). For the purposes of this exercise, let\u2019s define the behavior of get as follows: get takes one parameter, the index of the element to retrieve.<\/p>\n<p class=\"import-Normal\">Let\u2019s run through the scenarios. We could try to get an element from an empty list, a list with one element, a list with two elements, or a list with three elements. We could try to get the first element, a middle element, the last element, or an invalid index. Furthermore, an invalid index could be invalid because it is negative or greater than the number of elements in the list. Since we\u2019re getting by using an index, duplicate elements shouldn\u2019t affect anything.<\/p>\n\n<div class=\"textbox textbox--exercises\"><header class=\"textbox__header\">\n<p class=\"textbox__title\"><strong>Test Yourself<\/strong><\/p>\n\n<\/header>\n<div class=\"textbox__content\">\n<ul>\n \t<li class=\"import-Normal\">Which test(s) would cover multiple scenarios? Choose all that apply.\n<ul>\n \t<li class=\"import-Normal\">getting an element at index 3 from an empty list<\/li>\n \t<li class=\"import-Normal\">getting an element at index 0 from a list of size 1<\/li>\n \t<li class=\"import-Normal\">getting an element at index 0 from a list of size 4<\/li>\n \t<li class=\"import-Normal\">getting an element at index 3 from a list of size 5<\/li>\n<\/ul>\n<\/li>\n \t<li class=\"import-Normal\">Should you test a negative index on all four list sizes?<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<p class=\"import-Normal\">For this method, we could structure the tests to try to get all of the following indexes on each sized list:<\/p>\n\n<ul>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">a negative index<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">index 0<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">a middle index (if one exists)<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">the last index<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">an index too large<\/li>\n<\/ul>\n<p class=\"import-Normal\">The scenarios tested would be:<\/p>\n\n<ul>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">Empty list\n<ul>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">a negative index<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">an index too large<\/li>\n<\/ul>\n<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">One element list\n<ul>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">A negative index<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">Index 0, the first (and last) element<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">Index 1, an index too large<\/li>\n<\/ul>\n<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">Two element list\n<ul>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">A negative index<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">Index 0, the first element<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">Index 1, the last element<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">Index 2, an index too large<\/li>\n<\/ul>\n<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">Three element list\n<ul>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">A negative index<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">Index 0, the first element<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">Index 1, a middle element<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">Index 2, the last element<\/li>\n \t<li class=\"import-Normal\" style=\"text-indent: 18pt\">Index 3, an index too large<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p class=\"import-Normal\">It is assumed that a list with four or more elements will behave like a list with three elements, so there\u2019s no need to test a list larger than three elements. This assumption is based on the assumption that the list was implemented using a reasonable and efficient implementation and should hold up for linear lists. That is, for the purposes of testing, lists with three, four, five, or more elements are all considered [pb_glossary id=\"235\"]<strong>equivalent<\/strong> <strong>lists<\/strong>[\/pb_glossary].<\/p>\n<p class=\"import-Normal\">At this point, you may be concerned with how to create the most efficient tests so that you only test each scenario exactly once. In short, don\u2019t worry. While you don\u2019t want to run every single test multiple times, some redundancy and overlap is fine and could expose tricky bugs. For example, depending on how the list is implemented, getting the last element could be done differently for a one element vs. a three element list. Again, you want to ensure you\u2019ve tested the possible scenarios and have tested every line of code that you wrote.<\/p>\n\n<h4>Remove Method<\/h4>\n<p class=\"import-Normal\">Just like get, there are several different ways to remove from a list. For the purposes of this exercise, let\u2019s define the behavior of remove as follows: remove takes one parameter, the element to remove. If the element is found, that element is returned. If the element is not found, then an exception is thrown. If there are duplicate elements, the element that comes first in the list should be removed.<\/p>\n\n<div class=\"textbox textbox--exercises\"><header class=\"textbox__header\">\n<p class=\"textbox__title\"><strong>Test Yourself\n<\/strong><\/p>\n\n<\/header>\n<div class=\"textbox__content\">\n<ul>\n \t<li class=\"import-Normal\">What sized lists should you test?<\/li>\n \t<li class=\"import-Normal\">What is an invalid element in this context?<\/li>\n \t<li class=\"import-Normal\">From what positions should you test removing an element?<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<p class=\"import-Normal\">Similarly to how we tested <em>get<\/em>, there could be some redundancy in the tests as you\u2019d test removing elements in the same positions in different sized lists.<\/p>\n\n<\/div>","rendered":"<div class=\"testing-patterns\">\n<p class=\"import-Normal\">Now that we&#8217;ve explored the how-tos and whys, let&#8217;s take a look at how to determine what to test and how to know if it&#8217;s tested well enough. Remember, the ultimate goal of testing is to reach complete code coverage. Your tests should test every line of code at least once. However, you still need to consider the possible scenarios to ensure that you&#8217;ve written enough code! In this section, we&#8217;ll look at some common scenarios that could be tested.<\/p>\n<h3>User Input<\/h3>\n<p class=\"import-Normal\">For programs that take input from the user, the input that the user provides is a perfect source of errors. You can never trust the user! In these cases, you&#8217;ll want to test<\/p>\n<ul>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">valid input<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">invalid input\n<ul>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">which may include input that is out of range, the wrong type (like inputting letters instead of numbers), or unusable data<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p class=\"import-Normal\">Your program should work correctly with valid input. That&#8217;s a given. For invalid input, however, you need to decide if it makes sense for your program to handle the invalid input. For example, if your program has a menu, it makes sense to be able to recover if the user enters an invalid menu choice. Just let the user try again. On the other hand, if your program is supposed to perform some mathematical computation and the user enters characters, you have to decide if it makes sense to let the user try again or just let the program fail. What you don&#8217;t want to do is just push the error down the line; if the user gives you invalid input, your program should immediately handle it and get corrected input or it should fail LOUDLY. A bug based on an exception is much easier to find than a bug where your output is just wrong for some reason.<\/p>\n<h3>Classes<\/h3>\n<p class=\"import-Normal\">When testing a class, you should have at least one test per public method. As discussed earlier, since you can&#8217;t directly test private methods, their correctness has to be assessed indirectly. The tests you need to run depend on the method, but the considerations are similar to testing users&#8217; input. Here are some general things to consider.<\/p>\n<h4>Constructors<\/h4>\n<p class=\"import-Normal\">The purpose of a <a class=\"glossary-term\" aria-haspopup=\"dialog\" aria-describedby=\"definition\" href=\"#term_160_226\"><strong>constructor <\/strong><\/a>is to initialize the <strong><a class=\"glossary-term\" aria-haspopup=\"dialog\" aria-describedby=\"definition\" href=\"#term_160_227\">instance variables<\/a> <\/strong>and get the object ready to use. You should test that the instance variables are set correctly and any other set up has been properly done. This often involves using the getters (accessors).<\/p>\n<h4>Getters and Setters<\/h4>\n<p class=\"import-Normal\"><a class=\"glossary-term\" aria-haspopup=\"dialog\" aria-describedby=\"definition\" href=\"#term_160_228\"><strong>Getters <\/strong><\/a>and <a class=\"glossary-term\" aria-haspopup=\"dialog\" aria-describedby=\"definition\" href=\"#term_160_229\"><strong>setters<\/strong><\/a>, also known as <strong>accessors <\/strong>and <strong>mutators<\/strong>, are how other classes access and manipulate the values of the instance variables in a properly encapsulated class. The getters are often used as part of testing the constructors, so you don&#8217;t necessarily need specific tests for the getters. It is not wrong, however, to include such tests. Setters should be tested to ensure they properly update the variables, especially if the setter validates the new value. For example, if you have a method like <em>setAge<\/em> that verifies that the new age is positive, you&#8217;ll want to ensure that the age is only changed if the new value is valid. Setters are usually tested with the help of getters.<\/p>\n<div class=\"textbox textbox--exercises\">\n<header class=\"textbox__header\"><strong>Test Yourself<\/strong><\/header>\n<div class=\"textbox__content\">\n<ul>\n<li>What tests would you want to run on the <em>setAge<\/em> method described above?<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<h4>toString<\/h4>\n<p class=\"import-Normal\">This is another method that can be used to test other methods, depending on what&#8217;s used to create the String representation. Since the String representation of an object usually involves at least some of the instance variables, it can be a quick way to verify that changes have taken effect. For example, if you have a <em>List <\/em>class that represents a list and <em>toString<\/em> includes a print out of all of the elements, it can be a quick way to verify that the elements in the list are correct and in the correct order. It is worth testing <em>toString<\/em> on its own so that if its own test passes but another test using <em>toString<\/em> doesn&#8217;t, you can rule out the bug being in <em>toString<\/em>.<\/p>\n<p class=\"import-Normal\">You generally want to verify that <em>toString<\/em> is correct on a newly created object and after the object has been modified in such a way that the String representation would have changed.<\/p>\n<h4>Equality and Comparisons<\/h4>\n<p class=\"import-Normal\">While classes you write should always have constructors, getters and\/or setters, and a <em>toString<\/em>, your class may or may not have methods such as <em>equals, compareTo, <\/em>or <em>compare.<\/em> If your class does have these methods, you need to test them thoroughly! These are good examples of methods where you need to consider the scenarios in which these methods will be used. Those scenarios will help guide what tests you need to write.<\/p>\n<p class=\"import-Normal\">Consider the method <em>equals.<\/em> There are two possible outcomes of this method: the other object is equal to this object or the other object is not equal to this object. Each of these scenarios should be tested separately (i.e. in different test methods). Don&#8217;t stop there, though! If your <em>equals<\/em> method determines equality based on different instance variables, you should test that objects are or are not equal with varying combinations of equality amongst the instance variables. For example, suppose you have a <em>Dog<\/em> class that represents a dog and one Dog object is equal to another if and only if both Dogs have the same name and age. This means that a dog named Fido who is 7 years old would <em>not <\/em>be equal to a dog named Fido who is 3 years old. For an <em>equals<\/em> method like this, you would have the following tests:<\/p>\n<ul>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">equal objects where the names and ages are exactly the same<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">unequal objects where the names are different and the ages are different<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">unequal objects where the names are the same, but the ages are different<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">unequal objects where the ages are the same, but the names are different<\/li>\n<\/ul>\n<p class=\"import-Normal\">Similar considerations are required for methods like <em>compareTo.<\/em> A <em>compareTo<\/em> method should return the relative ordering between this object and the parameter object. It returns something negative if this object is less than the parameter, something positive if this object is greater than the parameter, and 0 if this object and the parameter are equal. Note that if <em>equals<\/em> considers objects equal, <em>compareTo<\/em> should also consider the objects equal.<\/p>\n<div class=\"textbox textbox--exercises\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\"><strong>Test Yourself<\/strong><\/p>\n<\/header>\n<div class=\"textbox__content\">\n<ul>\n<li class=\"import-Normal\">What are the three scenarios for compareTo?<\/li>\n<li class=\"import-Normal\">Given the Dog class, Dogs are ordered first by age, then by name. What should be returned when comparing Fido, age 3, and Spot, age 5?<\/li>\n<li class=\"import-Normal\">What is the minimum number of test methods you would need to fully test this compareTo?<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<h3>Loops<\/h3>\n<p class=\"import-Normal\">While you generally won&#8217;t just test a loop, these cases can help you determine how to test a method or program that contains a loop. The most common bugs with loops occur with respect to the stopping condition; <strong>off by one errors<\/strong> are quite common. These occur when <strong>boundary cases<\/strong> are not handled correctly. For example, if you have a loop that is supposed to run while the value of <em>i<\/em> is less than 10, 10 is the boundary condition because that&#8217;s the value that&#8217;s on the border of looping and not looping. You&#8217;d want to check that 9 loops but 10 does not. If 10 does loop but 11 doesn&#8217;t, that would be an off by one error. The basic values to consider when testing a loop are as follows.<\/p>\n<ul>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">the initial condition\n<ul>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">does the loop start on or with the correct condition<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">if it needs to, does the code do the right thing if the loop never runs?<\/li>\n<\/ul>\n<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">end condition\n<ul>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">does the loop stop correctly? Check the boundary cases and off-by one cases.<\/li>\n<\/ul>\n<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">side effects of the loop\n<ul>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">did the loop accomplish what it was supposed to do?<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<div class=\"textbox textbox--exercises\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\"><strong>Test Yourself<br \/>\n<\/strong><\/p>\n<\/header>\n<div class=\"textbox__content\">\n<ul>\n<li class=\"import-Normal\">Suppose you have a loop that sums the values from <em>min<\/em> to <em>max<\/em>. What test cases might you use?<\/li>\n<li class=\"import-Normal\">Suppose you have a loop that prints the elements of an array from the second element to the second to last element. What behavior do you expect from this loop?<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<h3>Lists<\/h3>\n<p class=\"import-Normal\">At some point in this class, you will write your own list. If you\u2019re not there yet, feel free to come back to this section when you are ready to start writing tests for your lists.<\/p>\n<p class=\"import-Normal\">A <a class=\"glossary-term\" aria-haspopup=\"dialog\" aria-describedby=\"definition\" href=\"#term_160_230\"><strong>list <\/strong><\/a>is a way to organize, store, and access data. To test your list, you must first determine how the user will be able to interact with the list. Does the user have <a class=\"glossary-term\" aria-haspopup=\"dialog\" aria-describedby=\"definition\" href=\"#term_160_231\"><strong>random access<\/strong> <\/a>to the elements? Can the user add or remove from the list? Can the user update elements? Be sure that you understand the mental model of your list before you being writing tests.<\/p>\n<p class=\"import-Normal\">Like testing a class, you will want to write tests for each public method. The tricky part about testing list methods is that you need to consider the state of the list and how that changes the behavior of the method. Here are some general guidelines.<\/p>\n<p class=\"import-Normal\">First, you should consider the state of the list. There are three basic states: the list is empty, the list has one or two items, and the list has three or more items. A list with three elements is the smallest list that has a first, middle, and last element. For testing purposes, we consider three elements to be a sufficiently full list <em>unless you need to test a structure that can become \u201cfull\u201d (like an array list).<\/em> If your list can become full, you need to test that it behaves correctly when it\u2019s full.<\/p>\n<p class=\"import-Normal\">Second, you should consider the location of the element. Again, there are three basic locations: the front, the middle, and the end. We consider all middle elements equally in the middle; that is, a middle element in a three element list should behave the same as a middle element in a ten element list. Both middle elements have an element on either side of it, so theoretically if your method works for one middle element, it ought to work for all middle elements.<\/p>\n<p class=\"import-Normal\">Let\u2019s look at a few examples. For these examples, we will assume we have an unordered, linear list with random access, e.g. a list. We will not assume any particular implementation. Lists will be represented using square brackets. An empty list looks like this: [ ]. A list containing a single element, A, looks like this: [ A ]. A list containing the elements A and B in that order looks like this: [ A, B ].<\/p>\n<p class=\"import-Normal\">Furthermore, when we discuss possible list scenarios in this class, we will use the following format:<\/p>\n<p class=\"import-Normal\" style=\"text-indent: 36pt\">Starting list \ud83e\udc6a Resulting list<\/p>\n<p class=\"import-Normal\">Thus, the scenario that we start with a list containing the element B and end up with a list containing B and C (in that order) would be represented as:<\/p>\n<p class=\"import-Normal\">[ B] \ud83e\udc6a [ B, C ].<\/p>\n<h4>Add Method<\/h4>\n<p class=\"import-Normal\">When you add to a list, you expect that the element you add ends up in the list. Let\u2019s assume that this add method adds the new element to the end of the list. Now we need to consider the possible scenarios. In how many ways could we add to a list?<\/p>\n<p class=\"import-Normal\">Considering the possible states of the list, we could add to an empty list. We could add to a list that has one element. We could add to a list that has two elements. We could add to a list that has three elements. A list with four or more elements should behave the same as a list with three elements.<\/p>\n<div class=\"textbox textbox--exercises\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\"><strong>Test Yourself<\/strong><\/p>\n<\/header>\n<ul>\n<li class=\"import-Normal\">Suppose you have an empty list, represented as [ ]. If you add element A to the list, what would you expect the resulting list to look like?<\/li>\n<li class=\"import-Normal\">Suppose you have a list with one element, represented as [ A ]. If you add element B to the list, what would you expect the resulting list to look like?<\/li>\n<\/ul>\n<\/div>\n<p class=\"import-Normal\">Next, consider the location of the element. The element could be in the first, middle, or last position. Remember that in this method, the element is always added to the end of the list.<\/p>\n<div class=\"textbox textbox--exercises\">\n<header class=\"textbox__header\"><strong>Test Yourself<\/strong><\/header>\n<div class=\"textbox__content\">\n<ul>\n<li class=\"import-Normal\">In what starting list(s) would adding a new element, A, result in the new element being the first element?<\/li>\n<li class=\"import-Normal\">In what starting list(s) would adding a new element, A, result in the new element being the middle element?<\/li>\n<li class=\"import-Normal\">In what starting list(s) would adding a new element, A, result in the new element being the last element?<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<p class=\"import-Normal\">How does all of this translate to test cases? We\u2019ve demonstrated that we really only have four possible scenarios: adding to an empty list, adding to a list with one element, adding to a list with two elements, and adding to a list with three elements. Adding to an empty list covers two scenarios: the list is empty and the newly added element is the first element. Adding to a one element list also covers two scenarios: the list has one element and the newly added element is the last element. The other scenarios are covered by adding to a list with two elements and adding to a list with three elements. For this method, it is impossible to add to the list and end up with the new element in the middle, so we don\u2019t need to worry about that scenario.<\/p>\n<div class=\"textbox textbox--exercises\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\"><strong>Test Yourself<\/strong><\/p>\n<\/header>\n<div class=\"textbox__content\">\n<ul>\n<li class=\"import-Normal\">What is the minimum number of test cases you would need to write to test this add method?<\/li>\n<li class=\"import-Normal\">List the scenarios that represent the test cases that should be written.\u00a0 Assume that the next unique letter will be added to the list (e.g. if the list already contains A, the next element added would be B. If the list already contains A and B, the next element added would be C, etc)<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<p class=\"import-Normal\">Now, we\u2019ve always assumed that we are adding unique elements. In a general list and in this particular method, duplicate items shouldn\u2019t cause a problem. However, it is good to keep in mind whether it matters if duplicate items exist and if they could cause problems. If it does matter, then adding a test that tests duplicated items is prudent!<\/p>\n<h4>Get Method<\/h4>\n<p class=\"import-Normal\">There are a number of different ways to get elements out of a list, depending on whether the list restricts access (like a <a class=\"glossary-term\" aria-haspopup=\"dialog\" aria-describedby=\"definition\" href=\"#term_160_232\"><strong>queue<\/strong><\/a>), if the elements have a unique index (like an <a class=\"glossary-term\" aria-haspopup=\"dialog\" aria-describedby=\"definition\" href=\"#term_160_233\"><strong>array<\/strong><\/a>), or if the elements are even expected to be in a particular order (like an unordered <a class=\"glossary-term\" aria-haspopup=\"dialog\" aria-describedby=\"definition\" href=\"#term_160_234\"><strong>set<\/strong><\/a>). For the purposes of this exercise, let\u2019s define the behavior of get as follows: get takes one parameter, the index of the element to retrieve.<\/p>\n<p class=\"import-Normal\">Let\u2019s run through the scenarios. We could try to get an element from an empty list, a list with one element, a list with two elements, or a list with three elements. We could try to get the first element, a middle element, the last element, or an invalid index. Furthermore, an invalid index could be invalid because it is negative or greater than the number of elements in the list. Since we\u2019re getting by using an index, duplicate elements shouldn\u2019t affect anything.<\/p>\n<div class=\"textbox textbox--exercises\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\"><strong>Test Yourself<\/strong><\/p>\n<\/header>\n<div class=\"textbox__content\">\n<ul>\n<li class=\"import-Normal\">Which test(s) would cover multiple scenarios? Choose all that apply.\n<ul>\n<li class=\"import-Normal\">getting an element at index 3 from an empty list<\/li>\n<li class=\"import-Normal\">getting an element at index 0 from a list of size 1<\/li>\n<li class=\"import-Normal\">getting an element at index 0 from a list of size 4<\/li>\n<li class=\"import-Normal\">getting an element at index 3 from a list of size 5<\/li>\n<\/ul>\n<\/li>\n<li class=\"import-Normal\">Should you test a negative index on all four list sizes?<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<p class=\"import-Normal\">For this method, we could structure the tests to try to get all of the following indexes on each sized list:<\/p>\n<ul>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">a negative index<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">index 0<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">a middle index (if one exists)<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">the last index<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">an index too large<\/li>\n<\/ul>\n<p class=\"import-Normal\">The scenarios tested would be:<\/p>\n<ul>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">Empty list\n<ul>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">a negative index<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">an index too large<\/li>\n<\/ul>\n<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">One element list\n<ul>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">A negative index<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">Index 0, the first (and last) element<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">Index 1, an index too large<\/li>\n<\/ul>\n<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">Two element list\n<ul>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">A negative index<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">Index 0, the first element<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">Index 1, the last element<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">Index 2, an index too large<\/li>\n<\/ul>\n<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">Three element list\n<ul>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">A negative index<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">Index 0, the first element<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">Index 1, a middle element<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">Index 2, the last element<\/li>\n<li class=\"import-Normal\" style=\"text-indent: 18pt\">Index 3, an index too large<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p class=\"import-Normal\">It is assumed that a list with four or more elements will behave like a list with three elements, so there\u2019s no need to test a list larger than three elements. This assumption is based on the assumption that the list was implemented using a reasonable and efficient implementation and should hold up for linear lists. That is, for the purposes of testing, lists with three, four, five, or more elements are all considered <a class=\"glossary-term\" aria-haspopup=\"dialog\" aria-describedby=\"definition\" href=\"#term_160_235\"><strong>equivalent<\/strong> <strong>lists<\/strong><\/a>.<\/p>\n<p class=\"import-Normal\">At this point, you may be concerned with how to create the most efficient tests so that you only test each scenario exactly once. In short, don\u2019t worry. While you don\u2019t want to run every single test multiple times, some redundancy and overlap is fine and could expose tricky bugs. For example, depending on how the list is implemented, getting the last element could be done differently for a one element vs. a three element list. Again, you want to ensure you\u2019ve tested the possible scenarios and have tested every line of code that you wrote.<\/p>\n<h4>Remove Method<\/h4>\n<p class=\"import-Normal\">Just like get, there are several different ways to remove from a list. For the purposes of this exercise, let\u2019s define the behavior of remove as follows: remove takes one parameter, the element to remove. If the element is found, that element is returned. If the element is not found, then an exception is thrown. If there are duplicate elements, the element that comes first in the list should be removed.<\/p>\n<div class=\"textbox textbox--exercises\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\"><strong>Test Yourself<br \/>\n<\/strong><\/p>\n<\/header>\n<div class=\"textbox__content\">\n<ul>\n<li class=\"import-Normal\">What sized lists should you test?<\/li>\n<li class=\"import-Normal\">What is an invalid element in this context?<\/li>\n<li class=\"import-Normal\">From what positions should you test removing an element?<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<p class=\"import-Normal\">Similarly to how we tested <em>get<\/em>, there could be some redundancy in the tests as you\u2019d test removing elements in the same positions in different sized lists.<\/p>\n<\/div>\n<div class=\"glossary\"><span class=\"screen-reader-text\" id=\"definition\">definition<\/span><template id=\"term_160_226\"><div class=\"glossary__definition\" role=\"dialog\" data-id=\"term_160_226\"><div tabindex=\"-1\"><p>A special kind of subroutine in a class whose purpose is to construct objects belonging to that class. A constructor is called using the new operator, and is not considered to be a \"method.\"<\/p>\n<\/div><button><span aria-hidden=\"true\">&times;<\/span><span class=\"screen-reader-text\">Close definition<\/span><\/button><\/div><\/template><template id=\"term_160_227\"><div class=\"glossary__definition\" role=\"dialog\" data-id=\"term_160_227\"><div tabindex=\"-1\"><p>A non-static variable in a class and hence a variable in any object that is an instance of that class.<\/p>\n<\/div><button><span aria-hidden=\"true\">&times;<\/span><span class=\"screen-reader-text\">Close definition<\/span><\/button><\/div><\/template><template id=\"term_160_228\"><div class=\"glossary__definition\" role=\"dialog\" data-id=\"term_160_228\"><div tabindex=\"-1\"><p>An instance method in a class that is used to read the value of some property of that class. Usually the property is just the value of some instance variable. By convention, a getter is named getXyz() where xyz is the name of the property.<\/p>\n<\/div><button><span aria-hidden=\"true\">&times;<\/span><span class=\"screen-reader-text\">Close definition<\/span><\/button><\/div><\/template><template id=\"term_160_229\"><div class=\"glossary__definition\" role=\"dialog\" data-id=\"term_160_229\"><div tabindex=\"-1\"><p>An instance method in a class that is used to set the value of some property of that class. Usually the property is just the value of some instance variable. By convention, a setter is named setXyz() where xyz is the name of the property.<\/p>\n<\/div><button><span aria-hidden=\"true\">&times;<\/span><span class=\"screen-reader-text\">Close definition<\/span><\/button><\/div><\/template><template id=\"term_160_230\"><div class=\"glossary__definition\" role=\"dialog\" data-id=\"term_160_230\"><div tabindex=\"-1\"><p>A finite, ordered sequence of data items known as elements. This is close to the mathematical concept of a sequence. Note that \u201cordered\u201d in this definition means that the list elements have position. It does not refer to the relationship between key values for the list elements (that is, \u201cordered\u201d does not mean \u201csorted\u201d).<\/p>\n<\/div><button><span aria-hidden=\"true\">&times;<\/span><span class=\"screen-reader-text\">Close definition<\/span><\/button><\/div><\/template><template id=\"term_160_231\"><div class=\"glossary__definition\" role=\"dialog\" data-id=\"term_160_231\"><div tabindex=\"-1\"><p>In file processing terminology, a disk access to a random position within the file. More generally, the ability to access an arbitrary element.<\/p>\n<\/div><button><span aria-hidden=\"true\">&times;<\/span><span class=\"screen-reader-text\">Close definition<\/span><\/button><\/div><\/template><template id=\"term_160_232\"><div class=\"glossary__definition\" role=\"dialog\" data-id=\"term_160_232\"><div tabindex=\"-1\"><p>A data structure consisting of a list of items, where items can only be added at one end and removed at the opposite end of the list.<\/p>\n<\/div><button><span aria-hidden=\"true\">&times;<\/span><span class=\"screen-reader-text\">Close definition<\/span><\/button><\/div><\/template><template id=\"term_160_233\"><div class=\"glossary__definition\" role=\"dialog\" data-id=\"term_160_233\"><div tabindex=\"-1\"><p>A list of items, sequentially numbered. Each item in the list can be identified by its index, that is, its sequence number. In Java, all the items in array must have the same type, called the base type of the array. An array is a random access data structure; that is, you can get directly at any item in the array at any time.<\/p>\n<\/div><button><span aria-hidden=\"true\">&times;<\/span><span class=\"screen-reader-text\">Close definition<\/span><\/button><\/div><\/template><template id=\"term_160_234\"><div class=\"glossary__definition\" role=\"dialog\" data-id=\"term_160_234\"><div tabindex=\"-1\"><p>A collection of objects which contains no duplicates. In Java, sets are represented by the generic interface Set<\/p>\n<\/div><button><span aria-hidden=\"true\">&times;<\/span><span class=\"screen-reader-text\">Close definition<\/span><\/button><\/div><\/template><template id=\"term_160_235\"><div class=\"glossary__definition\" role=\"dialog\" data-id=\"term_160_235\"><div tabindex=\"-1\"><p>For the purposes of testing, two lists are equivalent if the same sequence of steps occurs when a method is called (e.g. no special cases are triggered)<\/p>\n<\/div><button><span aria-hidden=\"true\">&times;<\/span><span class=\"screen-reader-text\">Close definition<\/span><\/button><\/div><\/template><\/div>","protected":false},"author":1,"menu_order":8,"template":"","meta":{"pb_show_title":"","pb_short_title":"","pb_subtitle":"","pb_authors":[],"pb_section_license":""},"chapter-type":[49],"contributor":[],"license":[],"class_list":["post-160","chapter","type-chapter","status-publish","hentry","chapter-type-numberless"],"part":145,"_links":{"self":[{"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/pressbooks\/v2\/chapters\/160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":2,"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/pressbooks\/v2\/chapters\/160\/revisions"}],"predecessor-version":[{"id":252,"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/pressbooks\/v2\/chapters\/160\/revisions\/252"}],"part":[{"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/pressbooks\/v2\/parts\/145"}],"metadata":[{"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/pressbooks\/v2\/chapters\/160\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/wp\/v2\/media?parent=160"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/pressbooks\/v2\/chapter-type?post=160"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/wp\/v2\/contributor?post=160"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/computersciencetwo\/wp-json\/wp\/v2\/license?post=160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}