SFWR ENG 3S03: Software Testing
|
|
- Branden Warner
- 5 years ago
- Views:
Transcription
1 (Slide 1 of 69) Dr. Ridha Khedri Writing in Department of Computing and Software, McMaster University Canada L8S 4L7, Hamilton, Ontario Acknowledgments: Material based on [HT03]
2 Unit Testing in Java with (Slide 2 of 69) 1 2 Excuses For Not Testing Units 3 Assertions as a testing technique Testing a Simple Method How to Run a Test 4 Writing in Structuring Unit Asserts Framework Test Writing in
3 Unit Testing in Java with (Slide 3 of 69) A unit test is a piece of code written by a developer/tester that exercises a very small, specific area of functionality of the code being tested Usually a unit test exercises some particular method in a particular context Add a large value to a sorted list, then confirm that this value appears at the end of the list Excuses For Not Testing Units Writing in Delete a pattern of characters from a string and then confirm that they are gone Unit testing techniques are needed for programmers and testers
4 Unit Testing in Java with (Slide 4 of 69) Fundamentally, you want to answer the question: Is the code fulfilling my intent? By building up confidence that the individual units work as expected, we can then proceed to assemble and test working systems Excuses For Not Testing Units Writing in We still need other forms of testing, and perhaps much more formal testing depending on your environment
5 Unit Testing in Java with (Slide 5 of 69) One nice side-effect of unit testing is that it helps you communicate the code s intended use A unit test behaves as executable documentation, showing how you expect the code to behave under the various conditions you have considered Excuses For Not Testing Units Writing in Team members can look at the tests for examples of how to use your code If someone comes across a test case that you haven t considered, they will be alerted quickly to that fact
6 Unit Testing in Java with (Slide 6 of 69) Unit testing is basically an easy practice to adopt However, there are some guidelines and common steps that you can follow to make it easier and more effective 1 Decide how to test the method in question With at least a rough idea of how to proceed, you proceed to write the test code itself (If you are testing your own code) Excuses For Not Testing Units Writing in 2 You run the test itself, and probably all the other tests in that (part of) the system if that can be done relatively quickly You want to get into the habit of looking at the test results and telling at a glance whether it all worked
7 Unit Testing in Java with (Slide 7 of 69) Excuses For Not Testing Units If I a programmer, It s not my job to test my code I am being paid to write code, not to write tests It takes too long to run the tests Excuses For Not Testing Units Writing in But it compiles! I feel guilty about putting testers and QA staff out of work
8 Unit Testing in Java with (Slide 8 of 69) Excuses For Not Testing Units If I am tester, I don t really know how the code is supposed to behave so I cannot test it It takes too much time to write the tests It takes too long to run the tests Excuses For Not Testing Units Writing in My company won t let me run unit tests on the live system (NOT THE CASE)
9 Unit Testing in Java with (Slide 9 of 69) Recall: a unit test is articulated into a piece of code it is to exercise another piece of code, and determines whether the other piece of code is behaving as expected or not How do you do that, exactly? Using Java Libraries: You can use an assertion, a simple method call that verifies that something is true Assertions as a testing technique Testing a Simple Method How to Run a Test Writing in Write your own assert method
10 Unit Testing in Java with (Slide 10 of 69) Assertions as a testing technique Sometimes, we want to make sure that a program satisfies a certain assumption at a given point The code for an assumption defines an assertion The assert statement allows us to specify an assertion about the program s behaviour The assumption is written as a Boolean expression Assertions as a testing technique Testing a Simple Method How to Run a Test Writing in The Boolean expression is evaluated during program execution If the expression evaluated to false, then an error message is generated the execution is aborted
11 Unit Testing in Java with Assertions as a testing technique Using java -ea FloatingPointArea3 Program Output 1 // Using a s s e r t i o n s to v e r i f y user input and c a l c u l a t e d values. i m p o r t j a v a. u t i l. Scanner ; 3 p u b l i c c l a s s F l o a t i n g P o i n t A r e a 3 { p u b l i c s t a t i c v o i d main ( S t r i n g [ ] a r g s ) { 5 Scanner keyboard = new Scanner ( System. i n ) ; 7 // Read r e c t a n g l e d i m e n s i o n s System. out. p r i n t ( En te r the r e c t a n g l e l e n g t h [ d e c i m a l number ] : ) ; 9 double l e n g t h = keyboard. nextdouble ( ) ; keyboard. n e x t L i n e ( ) ; 11 System. out. p r i n t ( Enter the r e c t a n g l e width [ d e c i m a l number ] : ) ; double width = keyboard. nextdouble ( ) ; 13 // V a l i d a t e u s e r i n p u t 15 a s s e r t l e n g t h > 0. 0 : The l e n g t h o f t h e r e c t a n g l e must be > 0. 0 ; // ( 1 ) a s s e r t width > 0.0 : The width o f t h e r e c t a n g l e must be > 0.0 ; // ( 2 ) 17 double area = l e n g t h width ; // C a l c u l a t e area of the r e c t a n g l e 19 // P r i n t t h e c o r r e c t answer 21 System. out. p r i n t f ( A r e c t a n g l e o f l e n g t h %.2 f cm. and width %.2 f cm. has + 23 a re a %.2 f sq. cm.%n, l e n g t h, width, a r e a ) ; 25 (Slide 11 of 69) Assertions as a testing technique Testing a Simple Method How to Run a Test Writing in Enter the rectangle length [decimal number]: -4 Enter the rectangle width [decimal number]: 1.4 Exception in thread "main" java.lang.assertionerror: The length of the rectangle must be > 0.0 at FloatingPointArea3.main(FloatingPointArea3.java:15)
12 Unit Testing in Java with Assertions as a testing technique Using java FloatingPointArea3 // Using a s s e r t i o n s to v e r i f y user input and c a l c u l a t e d values. 2 i m p o r t j a v a. u t i l. Scanner ; p u b l i c c l a s s F l o a t i n g P o i n t A r e a 3 { 4 p u b l i c s t a t i c v o i d main ( S t r i n g [ ] a r g s ) { Scanner keyboard = new Scanner ( System. i n ) ; 6 // Read r e c t a n g l e d i m e n s i o n s 8 System. out. p r i n t ( Enter the r e c t a n g l e l e n g t h [ d e c i m a l number ] : ) ; double l e n g t h = keyboard. nextdouble ( ) ; 10 keyboard. n e x t L i n e ( ) ; System. out. p r i n t ( En te r the r e c t a n g l e width [ d e c i m a l number ] : ) ; 12 double width = keyboard. nextdouble ( ) ; 14 // V a l i d a t e u s e r i n p u t a s s e r t l e n g t h > 0. 0 : The l e n g t h o f t h e r e c t a n g l e must be > 0. 0 ; // ( 1 ) 16 a s s e r t width > 0.0 : The width o f t h e r e c t a n g l e must be > 0.0 ; // ( 2 ) 18 double area = l e n g t h width ; // C a l c u l a t e area of the r e c t a n g l e 20 // P r i n t t h e c o r r e c t answer System. out. p r i n t f ( 22 A r e c t a n g l e o f l e n g t h %.2 f cm. and width %.2 f cm. has + a r e a %.2 f sq. cm.%n, 24 l e n g t h, width, a r e a ) ; 26 (Slide 12 of 69) Assertions as a testing technique Testing a Simple Method How to Run a Test Writing in Program Output Enter the rectangle length [decimal number]: -4 Enter the rectangle width [decimal number]: 1.4 A rectangle of length cm. and width 1.40 cm. has area sq. cm.
13 Unit Testing in Java with (Slide 13 of 69) Testing a Simple Method Assertions provide a useful testing technique that can help us detect errors early Assertions can be turned on when running the program for test purposes, and turned off when the program is shipped to the user The assertions can be turned on again by means of the -ea flag Assertions as a testing technique Testing a Simple Method How to Run a Test Writing in
14 Unit Testing in Java with (Slide 14 of 69) Testing a Simple Method FEST Assertions 2.0 is a Java library that provides a fluent interface for writing assertions Its main goal is to improve test code readability and make maintenance of tests easier FEST Assertions requires Java SE 6.0 or later and can be used with either or TestNG Assertions as a testing technique Testing a Simple Method How to Run a Test Writing in Currently, it provides assertions for the dat types: Object, String, Collection, Map, Primitives (boolean, int, char, etc.), Arrays of Object, Arrays of primitives, BufferedImage, Throwable, File, BigDecimal
15 Unit Testing in Java with Testing a Simple Method (Slide 15 of 69) You write your own assert function/method You use an assertion method that verifies that something is true Example: Write a method checks that the given boolean condition is true, and s the current test if it is not Assertions as a testing technique Testing a Simple Method How to Run a Test Writing in It might be implemented like the following
16 Unit Testing in Java with Testing a Simple Method (Slide 16 of 69) // 2 // a method a s s e r t T r u e // 4 // // C r e a t e d by Ridha K h e d r i on // // 8 p u b l i c v o i d a s s e r t T r u e ( boolean c o n d i t i o n ) { 10 i f (! c o n d i t i o n ) { a b o r t ( ) ; 12 1 i n t a = 2 ; 3 xx xxx xx x xxx x ; x x x xx xxx xxxx x ; 5 a s s e r t T r u e ( a == 2) ; xxxx xx xx xxx xx ; 7 xxxx xx xx xxx xx ; xxxx xx xx xxx xx ; Assertions as a testing technique Testing a Simple Method How to Run a Test Writing in
17 Unit Testing in Java with (Slide 17 of 69) Testing a Simple Method // 2 // a method a s s e r t T r u e // 4 // // C r e a t e d by Ridha K h e d r i on // // 8 p u b l i c v o i d a s s e r t T r u e ( b o o l e a n c o n d i t i o n ) { 10 i f (! c o n d i t i o n ) { a b o r t ( ) ; // 16 // we could write a method that takes two i n t e g e r parameters // 18 p u b l i c v o i d a s s e r t E q u a l s ( i n t a, i n t b ) { 20 a s s e r t T r u e ( a == b ) ; Assertions as a testing technique Testing a Simple Method How to Run a Test Writing in
18 Unit Testing in Java with (Slide 18 of 69) Testing a Simple Method Example int Largest.largest(int[] list); Given an array of numbers such as [7, 8, 9], this method should return 9 What other tests can you think of? r7, 8, 9s ÝÑ 9 r8, 9, 7s ÝÑ 9 r7, 9, 8, 9s ÝÑ 9 r1s ÝÑ 1 r 9, 8, 7s ÝÑ 7 Assertions as a testing technique Testing a Simple Method How to Run a Test Writing in
19 Unit Testing in Java with Testing a Simple Method 1 p u b l i c c l a s s L a r g e s t { 3 // // Return t h e l a r g e s t e l e m e n t i n a l i s t. 5 // l i s t A l i s t o f i n t e g e r s 7 r e t u r n The l a r g e s t number i n t h e g i v e n l i s t // 9 // // C r e a t e d by Ridha K h e d r i on // // p u b l i c s t a t i c i n t l a r g e s t ( i n t [ ] l i s t ) { i n t index, max=i n t e g e r. MAX VALUE ; 17 f o r ( i n d e x = 0 ; i n d e x < l i s t. l e n g t h 1; i n d e x++) { i f ( l i s t [ i n d e x ] > max ) { max = l i s t [ i n d e x ] ; return max ; 23 (Slide 19 of 69) Assertions as a testing technique Testing a Simple Method How to Run a Test Writing in
20 Unit Testing in Java with Testing a Simple Method (Slide 20 of 69) 2 i m p o r t j u n i t. framework. ; p u b l i c c l a s s T e s t L a r g e s t e x t e n d s TestCase { 4 p u b l i c T e s t L a r g e s t ( S t r i n g name ) { s u p e r ( name ) ; 6 8 p u b l i c v o i d t e s t S i m p l e ( ) { 10 a s s e r t E q u a l s ( 9, L a r g e s t. l a r g e s t ( new i n t [ ] {7,8,9) ) ; 12 Program Output Assertions as a testing technique Testing a Simple Method How to Run a Test Writing in There was 1 ure: 1) testsimple(testlargest)junit.framework.assertionfailederror: expected:<9> but was:< > at TestLargest.testSimple(TestLargest.java:11)
21 Unit Testing in Java with (Slide 21 of 69) Testing a Simple Method 2 p u b l i c c l a s s L a r g e s t { 4 p u b l i c s t a t i c i n t l a r g e s t ( i n t [ ] l i s t ) { i n t index, max = I n t e g e r. MIN VALUE ; 6 f o r ( i n d e x = 0 ; i n d e x < l i s t. l e n g t h 1; i n d e x++) { i f ( l i s t [ i n d e x ] > max ) { max = l i s t [ i n d e x ] ; 8 10 return max ; 12 Assertions as a testing technique Testing a Simple Method How to Run a Test Writing in
22 Unit Testing in Java with Testing a Simple Method (Slide 22 of 69) 1 i m p o r t j u n i t. framework. ; 3 p u b l i c c l a s s T e s t L a r g e s t e x t e n d s TestCase { 5 p u b l i c T e s t L a r g e s t ( S t r i n g name ) { s u p e r ( name ) ; 7 9 p u b l i c v o i d t e s t S i m p l e ( ) { a s s e r t E q u a l s ( 9, L a r g e s t. l a r g e s t ( new i n t [ ] {7,8,9) ) ; p u b l i c v o i d t e s t O r d e r ( ) { a s s e r t E q u a l s ( 9, L a r g e s t. l a r g e s t ( new i n t [ ] {9,8,7) ) ; 15 Assertions as a testing technique Testing a Simple Method How to Run a Test Writing in
23 Unit Testing in Java with (Slide 23 of 69) Testing a Simple Method 2 p u b l i c v o i d t e s t O r d e r ( ) { a s s e r t E q u a l s ( 9, L a r g e s t. l a r g e s t ( new i n t [ ] {9,8,7) ) ; 4 a s s e r t E q u a l s ( 9, L a r g e s t. l a r g e s t ( new i n t [ ] {7,9,8) ) ; 6 8 OR MORE TESTS p u b l i c v o i d t e s t O r d e r ( ) { a s s e r t E q u a l s ( 9, L a r g e s t. l a r g e s t ( new i n t [ ] {9,8,7) ) ; 12 a s s e r t E q u a l s ( 9, L a r g e s t. l a r g e s t ( new i n t [ ] {7,9,8) ) ; a s s e r t E q u a l s ( 9, L a r g e s t. l a r g e s t ( new i n t [ ] {7,8,9) ) ; 14 Program Output Assertions as a testing technique Testing a Simple Method How to Run a Test Writing in There was 1 ure: 1) testorder(testlargest)junit.framework.assertionfailederror: expected:<9> but was:<8> at TestLargest.testOrder(TestLargest.java:10)
24 Unit Testing in Java with Testing a Simple Method 2 p u b l i c c l a s s L a r g e s t { 4 p u b l i c s t a t i c i n t l a r g e s t ( i n t [ ] l i s t ) { i n t index, max = I n t e g e r. MIN VALUE ; 6 f o r ( i n d e x = 0 ; i n d e x < l i s t. l e n g t h 1; i n d e x++) { i f ( l i s t [ i n d e x ] > max ) { max = l i s t [ i n d e x ] ; 8 10 return max ; 12 1 p u b l i c c l a s s L a r g e s t { 3 p u b l i c s t a t i c i n t l a r g e s t ( i n t [ ] l i s t ) { 5 i n t index, max = I n t e g e r. MIN VALUE ; f o r ( i n d e x = 0 ; i n d e x < l i s t. l e n g t h ; i n d e x++) { 7 i f ( l i s t [ i n d e x ] > max ) { max = l i s t [ i n d e x ] ; 9 return max ; (Slide 24 of 69) Assertions as a testing technique Testing a Simple Method How to Run a Test Writing in
25 Unit Testing in Java with 1 Testing a Simple Method 3 import j u n i t. framework. ; 5 p u b l i c c l a s s T e s t L a r g e s t e x t e n d s TestCase { p u b l i c T e s t L a r g e s t ( S t r i n g name ) { 7 s u p e r ( name ) ; 9 11 p u b l i c void t e s t S i m p l e ( ) { a s s e r t E q u a l s (9, L a r g e s t. l a r g e s t (new i n t [ ] {7,8,9) ) ; p u b l i c v o i d testdups ( ) { (9, Largest. largest (new int [ ] {9,7,9,8) ) ; p u b l i c v o i d testone ( ) { a s s e r t E q u a l s (1, L a r g e s t. l a r g e s t (new i n t [ ] {1) ) ; p u b l i c void t e s t N e g a t i v e ( ) { int [ ] neglist = new int [ ] { 9, 8, 7; ( 7, L a r g e s t. l a r g e s t ( n e g L i s t ) ) ; 25 (Slide 25 of 69) Assertions as a testing technique Testing a Simple Method How to Run a Test Writing in 27 p u b l i c v o i d testempty ( ) { t r y { 29 L a r g e s t. l a r g e s t ( new i n t [ ] {) ; f a i l ( Should have thrown an e x c e p t i o n ) ; 31 c a t c h ( R u n t i m e E x c eption e ) { a s s e r t T r u e ( t r u e ) ; 33 35
26 Unit Testing in Java with (Slide 26 of 69) How to Run a Test If is integrated into your IDE, then running a test may be as easy as pressing a button and selecting from a list of available test classes Otherwise, you can always execute a TestRunner manually There are several flavours of test runners To run a GUI version that lets you pick and choose classes (and which remembers them from session to session), run the following class: Assertions as a testing technique Testing a Simple Method How to Run a Test Writing in java junit.swingui.testrunner
27 Unit Testing in Java with (Slide 27 of 69) How to Run a Test You will probably be able to run the junit.swingui.testrunner class from your IDE If not, run it from the command line using the jre or java command (as in previous slide) To run a test using the textual UI, use: java junit.textui.testrunner classname... Assertions as a testing technique Testing a Simple Method How to Run a Test Writing in For instance, to run the unit tests discussed in previous slides: javac Largest.java TestLargest.java java junit.textui.testrunner TestLargest
28 Unit Testing in Java with Writing in (Slide 28 of 69) We have looked at writing tests somewhat informally Now it is time to take a deeper look at the difference between test code and production code We look at all the various forms of s assert, the structure and composition of tests, etc. Writing in Structuring Unit Asserts Framework Test and
29 Unit Testing in Java with Writing in (Slide 29 of 69) Structuring Unit When writing test code, there are some naming conventions you need to follow If you have a method named createaccount that you want to test, then your first test method might be named testcreateaccount The method testcreateaccount will call createaccount with the necessary parameters and verify that createaccount works as specified Writing in Structuring Unit Asserts Framework Test and
30 Unit Testing in Java with Writing in (Slide 30 of 69) Structuring Unit You can have many test methods that exercise createaccount Customers or end-users will never see it or use it The production code must therefore not know anything about the test code Writing in Structuring Unit Asserts Framework Test and
31 Unit Testing in Java with Writing in Structuring Unit TestAccount.java testcreateaccount() testcreateacctdef() testcreateacctdup()... Internal Only Test Code Account.java CreateAccount() Delivered Prod. Code (Slide 31 of 69) Writing in Structuring Unit Asserts Framework Test and
32 Unit Testing in Java with Writing in (Slide 32 of 69) Structuring Unit The test code must be written to do a few things: Setup all conditions needed for testing (create any required objects, allocate any needed resources, etc.) Call the method to be tested Verify that the method to be tested functioned as expected Clean up after itself You write test code and compile it in the normal way (as you would any other bit of source code) It might happen to use some additional libraries, but otherwise it is just regular code Writing in Structuring Unit Asserts Framework Test and
33 Unit Testing in Java with Writing in (Slide 33 of 69) Structuring Unit When it is time to execute the code, remember that you never actually run the production code directly You won t be running it the way a user would You run the test code, which in turn exercises the production code under very carefully controlled conditions Writing in Structuring Unit Asserts Framework Test and
34 Unit Testing in Java with Writing in (Slide 34 of 69) Asserts There are (or we can write) some helper methods that assist us in determining whether a method under test is performing correctly or not We call all these methods asserts They let you assert that some condition is true We will take a look at each one of the assert methods that provides All of the following methods will record ures or errors, and report these through the classes Writing in Structuring Unit Asserts Framework Test and
35 Unit Testing in Java with Writing in (Slide 35 of 69) Asserts For the text version, that means an error message will be printed to the console The GUI version will show a red bar and supporting details to indicate a ure When a ure or error occurs, execution of the current test method is aborted Other tests within the same test class will still be run Asserts are the fundamental building block for unit tests Writing in Structuring Unit Asserts Framework Test and
36 Unit Testing in Java with Writing in (Slide 36 of 69) Asserts ([String message], expected, actual) This is the most-often used form of assert expected is a value you hope to see (typically hard-coded) actual is a value actually produced by the code under test message is an optional message that will be reported in the event of a ure Writing in Structuring Unit Asserts Framework Test and
37 Unit Testing in Java with Writing in (Slide 37 of 69) Asserts Any kind of object may be tested for equality In particular, you can compare the contents of strings using this method Different method signatures are also provided for all the native types (boolean, int, short, etc.) and Object Writing in Structuring Unit Asserts Framework Test and
38 Unit Testing in Java with Writing in (Slide 38 of 69) Asserts Be aware that the equals method for native arrays, does not compare the contents of the arrays (just the array reference itself) If you are using an assert to compare floating point numbers (floats or doubles in Java), you need to specify one additional piece of information, the tolerance This specifies just how close to?equals? you need the result to be For most business applications, 4 or 5 decimal places is probably enough For scientific apps, you may need much greater precision Writing in Structuring Unit Asserts Framework Test and
39 Unit Testing in Java with Writing in (Slide 39 of 69) Asserts Example ([String message], expected, actual, tolerance) ( Should be 3 1/3, 3.33, 10.0/3.0, 0.01); Writing in Structuring Unit Asserts Framework Test and
40 Unit Testing in Java with Writing in (Slide 40 of 69) Asserts ([String message], java.lang.object object) assertnotnull assertnotnull([string message], java.lang.object object) Asserts that the given object is null (or not null), ing otherwise Writing in Structuring Unit Asserts Framework Test and
41 Unit Testing in Java with Writing in (Slide 41 of 69) Asserts ([String message], expected, actual) assertnotsame assertnotsame([string message], expected, actual) The first asserts that expected and actual refer to the same object, and s the test if they do not The second asserts that expected and actual do not refer to the same object, and s the test if they are the same object Writing in Structuring Unit Asserts Framework Test and
42 Unit Testing in Java with Writing in (Slide 42 of 69) Asserts ([String message], boolean condition) Asserts that the given boolean condition is true, otherwise the test s assertfalse assertfalse([string message], boolean condition) Writing in Structuring Unit Asserts Framework Test and
43 Unit Testing in Java with Writing in (Slide 43 of 69) Asserts ([String message]) Fails the test immediately, with the optional message Often used to mark sections of code that should not be reached (for instance, after an exception is expected) Writing in Structuring Unit Asserts Framework Test and
44 Unit Testing in Java with Writing in Asserts You usually have multiple asserts in a given test method When an assert s, that test method will be aborted the remaining assertions in that method will not be executed this time You have to fix the ing test before you can proceed (Programmer) And you fix the next ing test. And the next. And so on. (Programmer) Programmer: Under no circumstances should you continue to add features when there are ing tests! (Slide 44 of 69) Writing in Structuring Unit Asserts Framework Test and
45 Unit Testing in Java with Writing in (Slide 45 of 69) Framework So far, we have just looked at the assert methods We need a little bit more of a structure around the asserts (a framework) Follows is a very simple piece of test code that illustrates the minimum framework we need to get started Writing in Structuring Unit Asserts Framework Test and
46 Unit Testing in Java with Writing in Framework (Slide 46 of 69) i m p o r t j u n i t. framework. ; 2 p u b l i c c l a s s T e s t S i m p l e e x t e n d s TestCase { 4 p u b l i c T e s t S i m p l e ( S t r i n g name ) { s u p e r ( name ) ; 6 8 p u b l i c v o i d t e s t A d d ( ) { a s s e r t E q u a l s ( 2, 1+1) ; 10 The import statement on line 1 brings in the necessary classes On line 3, we have the class defynition (each class that contains tests must extend TestCase as shown) The base class TestCase provides most of the unit-testing functionality that we need (including all of the assert methods) Writing in Structuring Unit Asserts Framework Test and
47 Unit Testing in Java with Writing in (Slide 47 of 69) Framework The base class requires a constructor that takes a String 1 i m p o r t j u n i t. framework. ; 3 p u b l i c c l a s s T e s t S i m p l e e x t e n d s TestCase { p u b l i c T e s t S i m p l e ( S t r i n g name ) { 5 s u p e r ( name ) ; 7 p u b l i c v o i d t e s t A d d ( ) { 9 a s s e r t E q u a l s ( 2, 1+1) ; 11 Finally, the test class contains a method named testadd on line 9 (It is the one we wanted to use in the example) All methods with names that begin with test will be run automatically by We can also specify particular methods to run by defining a suite method (To be discussed) Writing in Structuring Unit Asserts Framework Test and
48 Unit Testing in Java with Writing in (Slide 48 of 69) Framework 1 i m p o r t j u n i t. framework. ; 3 p u b l i c c l a s s T e s t S i m p l e e x t e n d s TestCase { p u b l i c T e s t S i m p l e ( S t r i n g name ) { 5 s u p e r ( name ) ; 7 p u b l i c v o i d t e s t A d d s ( ) { 9 a s s e r t E q u a l s ( 2, 1+1) ; a s s e r t E q u a l s ( 4, 2+2) ; 11 a s s e r t E q u a l s ( 8, 12+4) ; 13 In the previous example, we showed ONE test, using ONE assert, in ONE test method Inside a test method, we can place any number of asserts Writing in Structuring Unit Asserts Framework Test and
49 Unit Testing in Java with Writing in (Slide 49 of 69) Test Summary: A test class contains test methods Each method contains one or more assert statements A test class can also invoke other test classes: individual classes, packages, or even the whole system We can better structure our testing by creating test suites Writing in Structuring Unit Asserts Framework Test and
50 Unit Testing in Java with Writing in (Slide 50 of 69) Test Any test class can contain a static method named suite public static Test suite(); We can provide a suite() method to return any collection of tests we want Without a suite() method, runs all of the test... methods automatically We might also want to add particular tests by hand Writing in Structuring Unit Asserts Framework Test and
51 Unit Testing in Java with Writing in Test 1 import j u n i t. framework. ; 3 p u b l i c c l a s s TestClassTwo e x t e n d s TestCase { public TestClassTwo ( String method ) { 5 s u p e r ( method ) ; 7 // This one t a k e s a few h o u r s... 9 p u b l i c v o i d testlongrunner ( ) { 11 TSP t s p = new TSP ( ) ; // Load w i t h d e f a u l t c i t i e s (2300, tsp. shortestpath (50) ) ; // top p u b l i c void t e s t S h o r t T e s t ( ) { TSP t s p = new TSP ( ) ; // Load w i t h d e f a u l t c i t i e s 17 a s s e r t E q u a l s ( 14 0, t s p. s h o r t e s t P a t h ( 5 ) ) ; // top 5 19 p u b l i c void t e st A no th e rs h or tt e st ( ) { 21 TSP t s p = new TSP ( ) ; // Load w i t h d e f a u l t c i t i e s a s s e r t E q u a l s (5 86, t s p. s h o r t e s t P a t h (1 0 ) ) ; // top p u b l i c s t a t i c Test s u i t e ( ) { T e s t S u i t e s u i t e = new T e s t S u i t e ( ) ; 27 // Only i n c l u d e s h o r t tests suite. addtest ( 29 new TestClassTwo ( testshorttest ) ) ; 31 suite. addtest ( new TestClassTwo ( testanothershorttest ) 33 ) ; return s u i t e ; 35 (Slide 51 of 69) Writing in Structuring Unit Asserts Framework Test and
52 Unit Testing in Java with Writing in (Slide 52 of 69) Test Basic test Skeleton: Provides a mechanism to run test // package... 2 import j u n i t. framework. ; // Change a l l occurrences 4 // as a p p r o p r i a t e 6 p u b l i c c l a s s T e s t S k e l e t o n o f S k e l e t o n below e x t e n d s TestCase { / 8 Per method t e s t s e t up / 10 p u b l i c v o i d setup ( ) { 12 / 14 Per method t e s t t e a r down / 16 p u b l i c v o i d teardown ( ) { 18 / 20 Add t e s t s here : p u b l i c v o i d testname ( ) / p u b l i c T e s t S k e l e t o n ( S t r i n g name ) { 24 s u p e r ( name ) ; 26 / 28 D e f a u l t s u i t e method / 30 p u b l i c s t a t i c Test s u i t e ( ) { r e t u r n new T e s t S u i t e ( T e s t S k e l e t o n. c l a s s ) ; 32 // THE REST OF THE SKELETON i s on NEXT SLIDE Writing in Structuring Unit Asserts Framework Test and
53 Unit Testing in Java with Writing in (Slide 53 of 69) Test Basic test Skeleton... CONTINUED... 1 // Test S k e l e t o n CONTINUED from p r e v i o u s s l i d e 3 / Note main w i l l only be run when invoked i n d i v i d u a l l y from t h e command l i n e 5 ( not v i a A n t s J U n i t Task, e t c. ) / 7 p u b l i c s t a t i c v o i d main ( S t r i n g [ ] a r g s ) { T e s t S u i t e s u i t e = new T e s t S u i t e ( ) ; 9 i f ( a r g s. l e n g t h!= 0) { // Run s p e c i f i c t e s t s as i n d i c a t e d from t h e 11 // command l i n e f o r ( i n t i =0; i< a r g s. l e n g t h ; i ++) { 13 s u i t e. addtest ( new T e s t S k e l e t o n ( a r g s [ i ] ) ) ; 15 e l s e { // Dynamically discover a l l of them, or use 17 // u s e r d e f i n e d s u i t e suite. addtest ( TestSkeleton. suite ( ) ) ; 19 j u n i t. t e x t u i. TestRunner. run ( s u i t e ) ; 21 Writing in Structuring Unit Asserts Framework Test and
54 Unit Testing in Java with Writing in (Slide 54 of 69) Test The String parameter to the constructor lets a TestCase return a reference to a named test method We can use it to get references to the two short-running tests to populate our test suite You might want to have a higher-level test that is composed of test classes Writing in Structuring Unit Asserts Framework Test and
55 Unit Testing in Java with Writing in Test i m p o r t j u n i t. framework. ; 2 public c l a s s TestClassComposite extends TestCase { 4 public TestClassComposite ( String method ) { 6 s u p e r ( method ) ; 8 s t a t i c p u b l i c Test s u i t e ( ) { 10 T e s t S u i t e s u i t e = new T e s t S u i t e ( ) ; // Grab everything : 12 s u i t e. a d d T e s t S u i t e ( TestClassOne. c l a s s ) ; // Use t h e s u i t e method : 14 s u i t e. addtest ( TestClassTwo. s u i t e ( ) ) ; r e t u r n s u i t e ; 16 If you run TestClassComposite, we run the test methods: testaddition() from TestClassOne testsubtraction() from TestClassOne testshorttest() from TestClassTwo testanothershorttest() from TestClassTwo We can keep going with this scheme, by writing another class include TestClassComposite (Slide 55 of 69) Writing in Structuring Unit Asserts Framework Test and
56 Unit Testing in Java with Writing in (Slide 56 of 69) Test Each test should run independently of every other test This allows you to run any individual test at any time, in any order For this purpose, we may need to reset some parts of the testing environment in between tests, or clean up after a test has run s TestCase base class provides two methods that you can override to set up and then tear down the test s environment protected void setup(); (Called before each testxxxx ) protected void teardown(); (Called after each testxxxx ) Writing in Structuring Unit Asserts Framework Test and
57 Unit Testing in Java with Writing in (Slide 57 of 69) Test Example of Execution Order of Setup Code Writing in Structuring Unit Asserts Framework Test and
58 Unit Testing in Java with Writing in (Slide 58 of 69) Test Example: Overriding of setup and teardown 1 p u b l i c c l a s s TestDB e x t e n d s TestCase { p r i v a t e C o n n e c t i o n dbconn ; 3 p r o t e c t e d v o i d setup ( ) { 5 dbconn = new C o n n e c t i o n ( o r a c l e, 1521, Fred, f o o b a r ) ; dbconn. c o n n e c t ( ) ; 7 9 p r o t e c t e d v o i d teardown ( ) { dbconn. d i s c o n n e c t ( ) ; dbconn = n u l l ; p u b l i c v o i d t e s t A c c o u n t A c c e s s ( ) { // Uses dbconn 15 xxx xxx xxxxxx xxx xxxxxxxxx ; xx xxx xxx xxxx x xx xxxx ; p u b l i c v o i d t e s t E m p l o y e e A c c e s s ( ) { // Uses dbconn 21 xxx xxx xxxxxx xxx xxxxxxxxx ; xxxx x x xx xxx xx xxxx ; 23 Writing in Structuring Unit Asserts Framework Test and
59 Unit Testing in Java with Writing in (Slide 59 of 69) Test Normally per-test setup is all we need But in some circumstances, we may need to set something up or clean up after the entire test suite has run In this case, we need per-suite setup and tear-down Per-suite setup is a bit more complicated Provide a suite of the required tests Wrap it in a TestSetup object Writing in Structuring Unit Asserts Framework Test and
60 Unit Testing in Java with Writing in (Slide 60 of 69) Test Example: i m p o r t j u n i t. framework. ; i m p o r t j u n i t. e x t e n s i o n s. ; 2 p u b l i c c l a s s TestClassTwo e x t e n d s TestCase { p r i v a t e s t a t i c TSP t s p ; 4 p u b l i c TestClassTwo ( S t r i n g method ) { 6 s u p e r ( method ) ; 8 // This one t a k e s a few h o u r s p u b l i c v o i d t e s t L o n g R u n n e r ( ) { a s s e r t E q u a l s (2300, t s p. s h o r t e s t P a t h ( 5 0 ) ) ; p u b l i c v o i d t e s t S h o r t T e s t ( ) { a s s e r t E q u a l s ( 1 4 0, t s p. s h o r t e s t P a t h ( 5 ) ) ; p u b l i c v o i d t e s t A n o t h e r S h o r t T e s t ( ) { a s s e r t E q u a l s ( 5 8 6, t s p. s h o r t e s t P a t h ( 1 0 ) ) ; 20 // CONTINUED ON NEXT SLIDE Writing in Structuring Unit Asserts Framework Test and
61 Unit Testing in Java with Writing in Test // Continued from PREVIOUS SLIDE 2 p u b l i c s t a t i c Test s u i t e ( ) { 4 T e s t S u i t e s u i t e = new T e s t S u i t e ( ) ; // Only i n c l u d e s h o r t t e s t s 6 s u i t e. addtest ( new TestClassTwo ( t e s t S h o r t T e s t ) ) ; s u i t e. addtest ( new TestClassTwo ( t e s t A n o t h e r S h o r t T e s t ) ) ; 8 TestSetup wrapper = new TestSetup ( s u i t e ) { 10 p r o t e c t e d v o i d setup ( ) { onetimesetup ( ) ; p r o t e c t e d v o i d teardown ( ) { onetimeteardown ( ) ; 16 ; 18 r e t u r n wrapper ; 20 p u b l i c s t a t i c v o i d onetimesetup ( ) { 22 // one time i n i t i a l i z a t i o n code goes h e r e... t s p = new TSP ( ) ; 24 t s p. l o a d C i t i e s ( E a s t e r n S e a b o a r d ) ; 26 p u b l i c s t a t i c v o i d onetimeteardown ( ) { 28 // one time c l e a n u p code goes h e r e... t s p. r e l e a s e C i t i e s ( ) ; 30 (Slide 61 of 69) Writing in Structuring Unit Asserts Framework Test and
62 Unit Testing in Java with Writing in (Slide 62 of 69) Test and There are two kinds of exceptions that we might be interested in: Expected exceptions resulting from a test Unexpected exceptions from something that is gone wrong In a test, we want the method under test to throw an exception Writing in Structuring Unit Asserts Framework Test and
63 Unit Testing in Java with Writing in (Slide 63 of 69) Test and Consider a method named sortmylist() that is supposed to throw an exception if passed a null list 1 p u b l i c v o i d t e s t F o r E x c e p t i o n ( ) { t r y { 3 s o r t M y L i s t ( n u l l ) ; f a i l ( Should have thrown an e x c e p t i o n ) ; 5 catch ( RuntimeException e ) { a s s e r t T r u e ( t r u e ) ; 7 Writing in Structuring Unit Asserts Framework Test and
64 Unit Testing in Java with Writing in (Slide 64 of 69) For sets of tests with large amounts of test data Consider putting the test values and/or results in a separate data file that the unit test reads in It is a very complicated exercise The next example illustrate this usage of data files Writing in Structuring Unit Asserts Framework Test and
65 Unit Testing in Java with Writing in (Slide 65 of 69) The data file has a very simple format For example, each line contains a set of numbers The first number is the expected answer The numbers on the rest of the line are the arguments with which to test We allow a pound-sign (#) for comments, so that you can put notes in the test file Writing in Structuring Unit Asserts Framework Test and
66 Unit Testing in Java with Writing in (Slide 66 of 69) # # Simple tests: # # # Negative number tests: # # # Mixture: # # # Boundary conditions: # Writing in Structuring Unit Asserts Framework Test and
67 Unit Testing in Java with Writing in i m p o r t j u n i t. framework. ; 2 i m p o r t j a v a. i o. ; i m p o r t j a v a. u t i l. A r r a y L i s t ; 4 i m p o r t j a v a. u t i l. S t r i n g T o k e n i z e r ; 6 public c l a s s TestLargestDataFile extends TestCase { p u b l i c T e s t L a r g e s t D a t a F i l e ( S t r i n g name ) { 8 s u p e r ( name ) ; 10 / Run a l l t h e t e s t s i n t e s t d a t a. t x t ( does not t e s t 12 e x c e p t i o n c a s e ). We w i l l g e t an e r r o r i f any o f t h e f i l e I /O goes wrong. 14 / 16 p u b l i c void t e s t F r o m F i l e ( ) throws Exception { S t r i n g l i n e ; 18 B u f f e r e d R e a d e r r d r = new B u f f e r e d R e a d e r ( new F i l e R e a d e r ( t e s t d a t a. t x t ) ) ; 20 w h i l e ( ( l i n e = r d r. r e a d L i n e ( ) )!= n u l l ) { i f ( l i n e. s t a r t s W i t h ( # ) ) { // I g n o r e comments 22 continue ; 24 StringTokenizer st = new StringTokenizer ( l i n e ) ; 26 i f (! s t. hasmoretokens ( ) ) { c o n t i n u e ; // Blank l i n e //.... CONTINUED ON NEXT SLIDE (Slide 67 of 69) Writing in Structuring Unit Asserts Framework Test and
68 Unit Testing in Java with Writing in (Slide 68 of 69) 2 // CONTINUED FROM PREVIOUS SLIDE 4 // Get t h e e x p e c t e d v a l u e S t r i n g v a l = s t. nexttoken ( ) ; 6 i n t e x p e c t e d = I n t e g e r. v a l u e O f ( v a l ). i n t V a l u e ( ) ; // And t h e arguments to L a r g e s t 8 A r r a y L i s t a r g u m e n t l i s t = new A r r a y L i s t ( ) ; 10 w h i l e ( s t. hasmoretokens ( ) ) { a r g u m e n t l i s t. add ( I n t e g e r. v a l u e O f ( s t. nexttoken ( ) ) ) ; 12 // T r a n s f e r o b j e c t l i s t i n t o n a t i v e a r r a y 14 i n t [ ] arguments = new i n t [ a r g u m e n t l i s t. s i z e ( ) ] ; 16 f o r ( i n t i =0; i < a r g u m e n t l i s t. s i z e ( ) ; i ++) { arguments [ i ] = ( ( I n t e g e r ) a r g u m e n t l i s t. g e t ( i ) ). i n t V a l u e ( ) ; // And run t h e a s s e r t a s s e r t E q u a l s ( expected, L a r g e s t. l a r g e s t ( arguments ) ) ; Writing in Structuring Unit Asserts Framework Test and
69 References I (Slide 69 of 69) Andy Hunt and Dave Thomas, Pragmatic unit testing in java with junit, The Pragmatic Programmers, LLC, Writing in Structuring Unit Asserts Framework Test and
CS Exam 1 Study Guide and Practice Exam
CS 150 - Exam 1 Study Guide and Practice Exam September 11, 2017 Summary 1 Disclaimer 2 Variables 2.1 Primitive Types.............................................. 2.2 Suggestions, Warnings, and Resources.................................
More informationSoftware Testing Lecture 2
Software Testing Lecture 2 Justin Pearson September 25, 2014 1 / 1 Test Driven Development Test driven development (TDD) is a way of programming where all your development is driven by tests. Write tests
More informationObject Oriented Software Design (NTU, Class Even, Spring 2009) Final Examination Problem Sheet TIME: 06/16/2009, 14:20 17:20
Final Examination Problem Sheet TIME: 06/16/2009, 14:20 17:20 This is a closed-book exam. Any form of cheating or lying will not be tolerated. Students can get zero scores and/or fail the class and/or
More informationA GUI FOR EVOLVE ZAMS
A GUI FOR EVOLVE ZAMS D. R. Schlegel Computer Science Department Here the early work on a new user interface for the Evolve ZAMS stellar evolution code is presented. The initial goal of this project is
More informationComp 11 Lectures. Mike Shah. July 26, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures July 26, / 40
Comp 11 Lectures Mike Shah Tufts University July 26, 2017 Mike Shah (Tufts University) Comp 11 Lectures July 26, 2017 1 / 40 Please do not distribute or host these slides without prior permission. Mike
More informationACCESS TO SCIENCE, ENGINEERING AND AGRICULTURE: MATHEMATICS 1 MATH00030 SEMESTER / Lines and Their Equations
ACCESS TO SCIENCE, ENGINEERING AND AGRICULTURE: MATHEMATICS 1 MATH00030 SEMESTER 1 017/018 DR. ANTHONY BROWN. Lines and Their Equations.1. Slope of a Line and its y-intercept. In Euclidean geometry (where
More informationFACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING OBJECT ORIENTED PROGRAMMING DATE 07/2014 SESSION 8:00-10:00
FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING MODULE CAMPUS CSC2A10 OBJECT ORIENTED PROGRAMMING AUCKLAND PARK CAMPUS (APK) EXAM JULY 2014 DATE 07/2014 SESSION 8:00-10:00 ASSESOR(S)
More informationITI Introduction to Computing II
(with contributions from R. Holte) School of Electrical Engineering and Computer Science University of Ottawa Version of January 11, 2015 Please don t print these lecture notes unless you really need to!
More informationTuring Machines Part Three
Turing Machines Part Three What problems can we solve with a computer? What kind of computer? Very Important Terminology Let M be a Turing machine. M accepts a string w if it enters an accept state when
More informationLists, Stacks, and Queues (plus Priority Queues)
Lists, Stacks, and Queues (plus Priority Queues) The structures lists, stacks, and queues are composed of similar elements with different operations. Likewise, with mathematics: (Z, +, 0) vs. (Z,, 1) List
More information6.001 Recitation 22: Streams
6.001 Recitation 22: Streams RI: Gerald Dalley, dalleyg@mit.edu, 4 May 2007 http://people.csail.mit.edu/dalleyg/6.001/sp2007/ The three chief virtues of a programmer are: Laziness, Impatience and Hubris
More informationE23: Hotel Management System Wen Yunlu Hu Xing Chen Ke Tang Haoyuan Module: EEE 101
E23: Hotel Management System Author: 1302509 Zhao Ruimin 1301478 Wen Yunlu 1302575 Hu Xing 1301911 Chen Ke 1302599 Tang Haoyuan Module: EEE 101 Lecturer: Date: Dr.Lin December/22/2014 Contents Contents
More informationComp 11 Lectures. Mike Shah. July 12, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures July 12, / 33
Comp 11 Lectures Mike Shah Tufts University July 12, 2017 Mike Shah (Tufts University) Comp 11 Lectures July 12, 2017 1 / 33 Please do not distribute or host these slides without prior permission. Mike
More information1 Trees. Listing 1: Node with two child reference. public class ptwochildnode { protected Object data ; protected ptwochildnode l e f t, r i g h t ;
1 Trees The next major set of data structures belongs to what s called Trees. They are called that, because if you try to visualize the structure, it kind of looks like a tree (root, branches, and leafs).
More informationProblem Decomposition: One Professor s Approach to Coding
Problem Decomposition: One Professor s Approach to Coding zombie[1] zombie[3] Fewer Buuuuugs zombie[4] zombie[2] zombie[5] zombie[0] Fundamentals of Computer Science I Overview Problem Solving Understand
More informationCS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name:
CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, 2017 Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : If a child overrides
More informationFACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING OBJECT ORIENTED PROGRAMMING DATE 09/06/2014 SESSION 8:30-10:30
FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING MODULE CAMPUS CSC2A10 OBJECT ORIENTED PROGRAMMING AUCKLAND PARK CAMPUS (APK) EXAM JUNE 2014 DATE 09/06/2014 SESSION 8:30-10:30 ASSESOR(S)
More informationExtensibility Patterns: Extension Access
Design Patterns and Frameworks Dipl.-Medieninf. Christian Piechnick INF 2080 christian.piechnick@tu-dresden.de Exercise Sheet No. 5 Software Technology Group Institute for SMT Department of Computer Science
More information1 Overview of Simulink. 2 State-space equations
Modelling and simulation of engineering systems Simulink Exercise 1 - translational mechanical systems Dr. M. Turner (mct6@sun.engg.le.ac.uk 1 Overview of Simulink Simulink is a package which runs in the
More informationSYDE 112, LECTURE 7: Integration by Parts
SYDE 112, LECTURE 7: Integration by Parts 1 Integration By Parts Consider trying to take the integral of xe x dx. We could try to find a substitution but would quickly grow frustrated there is no substitution
More informationITI Introduction to Computing II
(with contributions from R. Holte) School of Electrical Engineering and Computer Science University of Ottawa Version of January 9, 2019 Please don t print these lecture notes unless you really need to!
More informationCONSTRUCTION OF sequence of rational approximations to sets of rational approximating sequences, all with the same tail behaviour Definition 1.
CONSTRUCTION OF R 1. MOTIVATION We are used to thinking of real numbers as successive approximations. For example, we write π = 3.14159... to mean that π is a real number which, accurate to 5 decimal places,
More informationIntroduction to Computing II (ITI 1121) MIDTERM EXAMINATION
Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of Engineering School of Electrical Engineering and Computer Science Identification
More informationIntroduction to Algebra: The First Week
Introduction to Algebra: The First Week Background: According to the thermostat on the wall, the temperature in the classroom right now is 72 degrees Fahrenheit. I want to write to my friend in Europe,
More informationOutline. PeerSim: Informal introduction. Resources. What is PeerSim? Alberto Montresor Gianluca Ciccarelli
Outline PeerSim: Informal introduction Alberto Montresor Gianluca Ciccarelli Networking group - University of Trento April 3, 2009 1 2 files structure 3 1 / 45 2 / 45 Resources What is PeerSim? These slides
More informationUnit 8: Sequ. ential Circuits
CPSC 121: Models of Computation Unit 8: Sequ ential Circuits Based on slides by Patrice Be lleville and Steve Wolfman Pre-Class Learning Goals By the start of class, you s hould be able to Trace the operation
More informationCourse Announcements. John Jannotti (cs32) Scope, Collections & Generics Feb 8, / 1
Course Announcements Stars is due tomorrow. Stars grades should be out by next Monday. Javascript lab out today. How you make interactive webby GUIs. Today we re going to cover a bit of a hodge podge.
More informationwhere Q is a finite set of states
Space Complexity So far most of our theoretical investigation on the performances of the various algorithms considered has focused on time. Another important dynamic complexity measure that can be associated
More informationPlease bring the task to your first physics lesson and hand it to the teacher.
Pre-enrolment task for 2014 entry Physics Why do I need to complete a pre-enrolment task? This bridging pack serves a number of purposes. It gives you practice in some of the important skills you will
More informationPHY221 Lab 2 - Experiencing Acceleration: Motion with constant acceleration; Logger Pro fits to displacement-time graphs
Page 1 PHY221 Lab 2 - Experiencing Acceleration: Motion with constant acceleration; Logger Pro fits to displacement-time graphs Print Your Name Print Your Partners' Names You will return this handout to
More informationChapter 5 Simplifying Formulas and Solving Equations
Chapter 5 Simplifying Formulas and Solving Equations Look at the geometry formula for Perimeter of a rectangle P = L W L W. Can this formula be written in a simpler way? If it is true, that we can simplify
More informationChapter 1 Review of Equations and Inequalities
Chapter 1 Review of Equations and Inequalities Part I Review of Basic Equations Recall that an equation is an expression with an equal sign in the middle. Also recall that, if a question asks you to solve
More informationOne sided tests. An example of a two sided alternative is what we ve been using for our two sample tests:
One sided tests So far all of our tests have been two sided. While this may be a bit easier to understand, this is often not the best way to do a hypothesis test. One simple thing that we can do to get
More information8 Square matrices continued: Determinants
8 Square matrices continued: Determinants 8.1 Introduction Determinants give us important information about square matrices, and, as we ll soon see, are essential for the computation of eigenvalues. You
More informationCS 163/164 - Exam 1 Study Guide and Practice Exam
CS 163/164 - Exam 1 Study Guide and Practice Exam September 11, 2017 Summary 1 Disclaimer 2 Variables 2.1 Primitive Types.............................................. 2.2 Strings...................................................
More informationCS 453 Operating Systems. Lecture 7 : Deadlock
CS 453 Operating Systems Lecture 7 : Deadlock 1 What is Deadlock? Every New Yorker knows what a gridlock alert is - it s one of those days when there is so much traffic that nobody can move. Everything
More informationGetting Started with Communications Engineering
1 Linear algebra is the algebra of linear equations: the term linear being used in the same sense as in linear functions, such as: which is the equation of a straight line. y ax c (0.1) Of course, if we
More informationRegression, part II. I. What does it all mean? A) Notice that so far all we ve done is math.
Regression, part II I. What does it all mean? A) Notice that so far all we ve done is math. 1) One can calculate the Least Squares Regression Line for anything, regardless of any assumptions. 2) But, if
More informationDistributed Systems Part II Solution to Exercise Sheet 10
Distributed Computing HS 2012 Prof. R. Wattenhofer / C. Decker Distributed Systems Part II Solution to Exercise Sheet 10 1 Spin Locks A read-write lock is a lock that allows either multiple processes to
More informationHypothesis testing I. - In particular, we are talking about statistical hypotheses. [get everyone s finger length!] n =
Hypothesis testing I I. What is hypothesis testing? [Note we re temporarily bouncing around in the book a lot! Things will settle down again in a week or so] - Exactly what it says. We develop a hypothesis,
More information35. SOLVING ABSOLUTE VALUE EQUATIONS
35. SOLVING ABSOLUTE VALUE EQUATIONS solving equations involving absolute value This section presents the tool needed to solve absolute value equations like these: x = 5 2 3x = 7 5 2 3 4x = 7 Each of these
More informationTechniques of Java Programming
Legi-Nr.:... Techniques of Java Programming ETH Zurich Date: 9 May 008 Family name, first name:... Student number:... I confirm with my signature, that I was able to take this exam under regular circumstances
More informationSoftwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany
Softwaretechnik Lecture 13: Design by Contract Peter Thiemann University of Freiburg, Germany 25.06.2012 Table of Contents Design by Contract Contracts for Procedural Programs Contracts for Object-Oriented
More informationSFWR ENG/COMP SCI 2S03 Principles of Programming
(Slide 1 of 23) Dr. Ridha Khedri Department of Computing and Software, McMaster University Canada L8S 4L7, Hamilton, Ontario Acknowledgments: Material based on Java actually: A Comprehensive Primer in
More informationTe s t D r i v e n D e v e l o p m e n t. C h a m i l J e e w a n t h a
Te s t D r i v e n D e v e l o p m e n t C h a m i l J e e w a n t h a W h a t i s a U n i t Te s t? Select the smallest piece of testable software in the application Isolate it from the rest of the code
More informationConnect the Vernier spectrometer to your lap top computer and power the spectrometer if necessary. Start LoggerPro on your computer.
Connect the Vernier spectrometer to your lap top computer and power the spectrometer if necessary. Start LoggerPro on your computer. The screen shown in Fig. 1 may be displayed. If status line displays
More information8. TRANSFORMING TOOL #1 (the Addition Property of Equality)
8 TRANSFORMING TOOL #1 (the Addition Property of Equality) sentences that look different, but always have the same truth values What can you DO to a sentence that will make it LOOK different, but not change
More informationCS4026 Formal Models of Computation
CS4026 Formal Models of Computation Turing Machines Turing Machines Abstract but accurate model of computers Proposed by Alan Turing in 1936 There weren t computers back then! Turing s motivation: find
More informationPart 1: You are given the following system of two equations: x + 2y = 16 3x 4y = 2
Solving Systems of Equations Algebraically Teacher Notes Comment: As students solve equations throughout this task, have them continue to explain each step using properties of operations or properties
More informationBasic Java OOP 10/12/2015. Department of Computer Science & Information Engineering. National Taiwan University
Basic Java OOP 10/12/2015 Hsuan-Tien Lin ( 林軒田 ) htlin@csie.ntu.edu.tw Department of Computer Science & Information Engineering National Taiwan University ( 國立台灣大學資訊工程系 ) Hsuan-Tien Lin (NTU CSIE) Basic
More informationGCA AS200 Job Preparation
GCA AS200 Job Preparation The GCA AutoStep 200 wafer stepper is an easy to use instrument capable of very clean lithography with a typical resolution of 0.75 µm, and even 0.6 µm with some optimization.
More informationBlack-Box Testing Techniques III
Black-Box Testing Techniques III Software Testing and Verification Lecture 6 Prepared by Stephen M. Thebaut, Ph.D. University of Florida Another Cause-Effect Example: Symbol Table Storage Specification
More informationCS 124 Math Review Section January 29, 2018
CS 124 Math Review Section CS 124 is more math intensive than most of the introductory courses in the department. You re going to need to be able to do two things: 1. Perform some clever calculations to
More informationAlgebra Exam. Solutions and Grading Guide
Algebra Exam Solutions and Grading Guide You should use this grading guide to carefully grade your own exam, trying to be as objective as possible about what score the TAs would give your responses. Full
More informationSoftware Testing Lecture 7 Property Based Testing. Justin Pearson
Software Testing Lecture 7 Property Based Testing Justin Pearson 2017 1 / 13 When are there enough unit tests? Lets look at a really simple example. import u n i t t e s t def add ( x, y ) : return x+y
More informationv Prerequisite Tutorials GSSHA WMS Basics Watershed Delineation using DEMs and 2D Grid Generation Time minutes
v. 10.1 WMS 10.1 Tutorial GSSHA WMS Basics Creating Feature Objects and Mapping Attributes to the 2D Grid Populate hydrologic parameters in a GSSHA model using land use and soil data Objectives This tutorial
More informationCSCE 155N Fall Homework Assignment 2: Stress-Strain Curve. Assigned: September 11, 2012 Due: October 02, 2012
CSCE 155N Fall 2012 Homework Assignment 2: Stress-Strain Curve Assigned: September 11, 2012 Due: October 02, 2012 Note: This assignment is to be completed individually - collaboration is strictly prohibited.
More informationINTRODUCTION. This is not a full c-programming course. It is not even a full 'Java to c' programming course.
C PROGRAMMING 1 INTRODUCTION This is not a full c-programming course. It is not even a full 'Java to c' programming course. 2 LITTERATURE 3. 1 FOR C-PROGRAMMING The C Programming Language (Kernighan and
More informationInformation System Design IT60105
Information System Design IT60105 Lecture 8 Use Case Diagrams Lecture #8 What is a use-case diagram? Example: On-line purchase (OLP) system Use-case diagram of OLP system Different components in a use-case
More informationINF 4140: Models of Concurrency Series 3
Universitetet i Oslo Institutt for Informatikk PMA Olaf Owe, Martin Steffen, Toktam Ramezani INF 4140: Models of Concurrency Høst 2016 Series 3 14. 9. 2016 Topic: Semaphores (Exercises with hints for solution)
More informationSoftwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany
Softwaretechnik Lecture 13: Design by Contract Peter Thiemann University of Freiburg, Germany 25.06.2012 Table of Contents Design by Contract Contracts for Procedural Programs Contracts for Object-Oriented
More informationAlgebra & Trig Review
Algebra & Trig Review 1 Algebra & Trig Review This review was originally written for my Calculus I class, but it should be accessible to anyone needing a review in some basic algebra and trig topics. The
More informationSoftware Testing Lecture 5. Justin Pearson
Software Testing Lecture 5 Justin Pearson 2017 1 / 34 Covering Logical Expressions Logic expression show up in many situations Covering logical expressions have a long history, many are the covering criteria
More informationOutline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University
COMP SCI / SFWR ENG 2S03 Department of Computing and Software McMaster University Week 10: November 7 - November 11 Outline 1 Resource 2 Introduction Nodes Illustration 3 Usage Accessing and Modifying
More informationIntroducing Proof 1. hsn.uk.net. Contents
Contents 1 1 Introduction 1 What is proof? 1 Statements, Definitions and Euler Diagrams 1 Statements 1 Definitions Our first proof Euler diagrams 4 3 Logical Connectives 5 Negation 6 Conjunction 7 Disjunction
More informationNewton s Cooling Model in Matlab and the Cooling Project!
Newton s Cooling Model in Matlab and the Cooling Project! James K. Peterson Department of Biological Sciences and Department of Mathematical Sciences Clemson University March 10, 2014 Outline Your Newton
More informationAdvanced Structural Analysis Prof. Devdas Menon Department of Civil Engineering Indian Institute of Technology, Madras
Advanced Structural Analysis Prof. Devdas Menon Department of Civil Engineering Indian Institute of Technology, Madras Module No. # 5.4 Lecture No. # 30 Matrix Analysis of Beams and Grids (Refer Slide
More informationLesson 21 Not So Dramatic Quadratics
STUDENT MANUAL ALGEBRA II / LESSON 21 Lesson 21 Not So Dramatic Quadratics Quadratic equations are probably one of the most popular types of equations that you ll see in algebra. A quadratic equation has
More informationAMS 132: Discussion Section 2
Prof. David Draper Department of Applied Mathematics and Statistics University of California, Santa Cruz AMS 132: Discussion Section 2 All computer operations in this course will be described for the Windows
More informationCityGML XFM Application Template Documentation. Bentley Map V8i (SELECTseries 2)
CityGML XFM Application Template Documentation Bentley Map V8i (SELECTseries 2) Table of Contents Introduction to CityGML 1 CityGML XFM Application Template 2 Requirements 2 Finding Documentation 2 To
More informationLecture 10: Powers of Matrices, Difference Equations
Lecture 10: Powers of Matrices, Difference Equations Difference Equations A difference equation, also sometimes called a recurrence equation is an equation that defines a sequence recursively, i.e. each
More informationNew Approaches to the Development of GC/MS Selected Ion Monitoring Acquisition and Quantitation Methods Technique/Technology
New Approaches to the Development of GC/MS Selected Ion Monitoring Acquisition and Quantitation Methods Technique/Technology Gas Chromatography/Mass Spectrometry Author Harry Prest 1601 California Avenue
More informationUncertainty. Michael Peters December 27, 2013
Uncertainty Michael Peters December 27, 20 Lotteries In many problems in economics, people are forced to make decisions without knowing exactly what the consequences will be. For example, when you buy
More informationBasics of Proofs. 1 The Basics. 2 Proof Strategies. 2.1 Understand What s Going On
Basics of Proofs The Putnam is a proof based exam and will expect you to write proofs in your solutions Similarly, Math 96 will also require you to write proofs in your homework solutions If you ve seen
More informationEXPERIMENTAL PROJECT Rigid Pendulum Experiment
EXPERIMENTAL PROJECT 2012-2013 Rigid Pendulum Experiment INTRODUCTION The simple pendulum is familiar idea to many students as they will have seen a small mass swinging from side to side at the end of
More informationExercise 1 (15 points)
Exam System Validation (214012) 8:45-12:15, 25-06-2010 The exercises are worth a total of 90 points. The final grade is 10+pts 10. The exam is open book: copies of slides/papers/notes/etc. are allowed.
More informationIntroduction to Turing Machines. Reading: Chapters 8 & 9
Introduction to Turing Machines Reading: Chapters 8 & 9 1 Turing Machines (TM) Generalize the class of CFLs: Recursively Enumerable Languages Recursive Languages Context-Free Languages Regular Languages
More informationActivities, Fragments and Intents
Mobile App Development 1 2 Design Principles 3 1 2 Design Principles 3 Manifest file Outline AndroidManifest.xml XML file Contains name of the application and a default package, Sets up the various permissions
More informationNondeterministic finite automata
Lecture 3 Nondeterministic finite automata This lecture is focused on the nondeterministic finite automata (NFA) model and its relationship to the DFA model. Nondeterminism is an important concept in the
More informationTutorial Three: Loops and Conditionals
Tutorial Three: Loops and Conditionals Imad Pasha Chris Agostino February 18, 2015 1 Introduction In lecture Monday we learned that combinations of conditionals and loops could make our code much more
More informationCS-140 Fall 2018 Test 2 Version Practice Nov. 12, 2018
CS-140 Fall 2018 Test 2 Version Practice Nov. 12, 2018 Name: 1. (10 points) For the following, Check T if the statement is true, or F if the statement is false. (a) T X F : If a child overrides its parent
More informationhighlights proof by contradiction what about the real numbers?
CSE 311: Foundations of Computing Fall 2013 Lecture 27: Turing machines and decidability highlights Cardinality A set S is countableiffwe can writeit as S={s 1, s 2, s 3,...} indexed by N Set of rationals
More informationECEN 651: Microprogrammed Control of Digital Systems Department of Electrical and Computer Engineering Texas A&M University
ECEN 651: Microprogrammed Control of Digital Systems Department of Electrical and Computer Engineering Texas A&M University Prof. Mi Lu TA: Ehsan Rohani Laboratory Exercise #4 MIPS Assembly and Simulation
More informationMA 1128: Lecture 08 03/02/2018. Linear Equations from Graphs And Linear Inequalities
MA 1128: Lecture 08 03/02/2018 Linear Equations from Graphs And Linear Inequalities Linear Equations from Graphs Given a line, we would like to be able to come up with an equation for it. I ll go over
More informationNonregular Languages
Nonregular Languages Recap from Last Time Theorem: The following are all equivalent: L is a regular language. There is a DFA D such that L( D) = L. There is an NFA N such that L( N) = L. There is a regular
More informationCSE 331 Winter 2018 Reasoning About Code I
CSE 331 Winter 2018 Reasoning About Code I Notes by Krysta Yousoufian Original lectures by Hal Perkins Additional contributions from Michael Ernst, David Notkin, and Dan Grossman These notes cover most
More informationClojure Concurrency Constructs, Part Two. CSCI 5828: Foundations of Software Engineering Lecture 13 10/07/2014
Clojure Concurrency Constructs, Part Two CSCI 5828: Foundations of Software Engineering Lecture 13 10/07/2014 1 Goals Cover the material presented in Chapter 4, of our concurrency textbook In particular,
More informationMA554 Assessment 1 Cosets and Lagrange s theorem
MA554 Assessment 1 Cosets and Lagrange s theorem These are notes on cosets and Lagrange s theorem; they go over some material from the lectures again, and they have some new material it is all examinable,
More information1 Introduction & Objective
Signal Processing First Lab 13: Numerical Evaluation of Fourier Series Pre-Lab and Warm-Up: You should read at least the Pre-Lab and Warm-up sections of this lab assignment and go over all exercises in
More information30. TRANSFORMING TOOL #1 (the Addition Property of Equality)
30 TRANSFORMING TOOL #1 (the Addition Property of Equality) sentences that look different, but always have the same truth values What can you DO to a sentence that will make it LOOK different, but not
More information4.4 The Calendar program
4.4. THE CALENDAR PROGRAM 109 4.4 The Calendar program To illustrate the power of functions, in this section we will develop a useful program that allows the user to input a date or a month or a year.
More informationUsing Microsoft Excel
Using Microsoft Excel Objective: Students will gain familiarity with using Excel to record data, display data properly, use built-in formulae to do calculations, and plot and fit data with linear functions.
More informationR I T. Title: GCA Stepper Operations. Semiconductor & Microsystems Fabrication Laboratory Revision: F Rev Date: 08/09/ SCOPE
Approved by: Process Engineer / / / / Equipment Engineer 1 SCOPE The purpose of this document is to detail the use of the GCA Stepper. All users are expected to have read and understood this document.
More informationComputer Science Introductory Course MSc - Introduction to Java
Computer Science Introductory Course MSc - Introduction to Java Lecture 1: Diving into java Pablo Oliveira ENST Outline 1 Introduction 2 Primitive types 3 Operators 4 5 Control Flow
More informationMITOCW ocw-18_02-f07-lec02_220k
MITOCW ocw-18_02-f07-lec02_220k The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free.
More informationMath 38: Graph Theory Spring 2004 Dartmouth College. On Writing Proofs. 1 Introduction. 2 Finding A Solution
Math 38: Graph Theory Spring 2004 Dartmouth College 1 Introduction On Writing Proofs What constitutes a well-written proof? A simple but rather vague answer is that a well-written proof is both clear and
More informationbw2-regional Documentation
bw2-regional Documentation Release 0.2 Chris Mutel July 05, 2015 Contents 1 Spatial scales (geocollections) 3 2 Intersections 5 3 Import regionalized characterization factors 7 3.1 Data and data formats..........................................
More informationPhysics 6A Lab Experiment 6
Biceps Muscle Model Physics 6A Lab Experiment 6 Introduction This lab will begin with some warm-up exercises to familiarize yourself with the theory, as well as the experimental setup. Then you ll move
More informationIn this episode of The Verification Corner, Rustan Leino talks about Loop Invariants. He gives a brief summary of the theoretical foundations and
In this episode of The Verification Corner, Rustan Leino talks about Loop Invariants. He gives a brief summary of the theoretical foundations and shows how a program can sometimes be systematically constructed
More information#29: Logarithm review May 16, 2009
#29: Logarithm review May 16, 2009 This week we re going to spend some time reviewing. I say re- view since you ve probably seen them before in theory, but if my experience is any guide, it s quite likely
More information