CS 2110 Lecture Notes - Lecture 3: Junit, Precondition, Class Invariant
Document Summary
We"(cid:448)e see(cid:374) pu(cid:271)li(cid:272) (cid:272)lasses, (cid:271)ut there is o much more. We"(cid:448)e see(cid:374) t(cid:449)o t(cid:455)pes of (cid:373)ethods for (cid:272)lasses. In eclipse, we make a new java project. Go to the src folder, create new class. Before class header, we write a specification for the class. Then when we declare certain attributes of the class, we include their invariants as a comment next to them. We do not want users to access these variables. Then we add stuff that we desire, like a tostring() method that gives us the object of ti(cid:373)e i(cid:374) a stri(cid:374)g of the for(cid:373) (cid:862)(cid:1004)(cid:1007):(cid:1006)(cid:1005)(cid:863) We write retur(cid:374) hr + (cid:862):(cid:863) (cid:373)(cid:374); But wait! hr and min are ints! File > new > junit test case (use version 4) Then we create our test cases as needed, typically using assert statements. This will fail with our previous definition for tostring() If we have hr = 0, min = 0, then our previous tostring will retur(cid:374) (cid:862)(cid:1004):(cid:1004)(cid:863)