From leavens@cs.iastate.edu Wed Apr 9 13:11:30 2003 Date: Wed, 9 Apr 2003 13:09:27 -0500 (CDT) From: Gary T. Leavens To: Com S 362 students and staff -- Brian Thola , Yoonsik Cheon , com_s_362@cs.iastate.edu, David Avila , Derek James Light , Gaurav Dhiman , Kevin J Gaul , Les Miller , Olatunde Olatunji , Ritesh Desai , Tongjie Chen Subject: COMS 362: New release of JML 3.7 Hi all, If you have previously downloaded JML to your home computer, you should reinstall the latest version, just released today. This is available from the JML web page: http://www.jmlspecs.org/ or from the sourceforge project page for JML http://sourceforge.net/projects/jmlspecs or directly from sourceforge.net http://sourceforge.net/project/showfiles.php?group_id=65346 in the file JML.3.7.tgz. This is a gzipped tar file. You can use a tool like winzip to deal with unpacking it. See the file README.html in the JML directory of the release for instructions on how to complete the installation. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ---------------------------------------------- From leavens@cs.iastate.edu Sat Apr 12 08:16:51 2003 Date: Sat, 12 Apr 2003 08:15:16 -0500 (CDT) From: Gary T. Leavens To: Kevin Wendzel Cc: Staff for Com S 362 Subject: Re: CS 362: Help with Assignment 9 Hi Kevin, On Fri, 11 Apr 2003 kwendzel@iastate.edu wrote: > I have two questions so far about the homework for you. First, how am I > supposed to declare new variables of type HistoricalData? Right now I am > using the syntax: > > HistoricalData data = new HistoricalData; > > except that obviously it wants "(string)" after "new HistoricalData" but no > matter what I try, I get errors. The only constructor HistoricalData has is the default (implicit) constructor with no arguments. So you would write: HistoricalData data = new HistoricalData(); for example. > Second, how am I supposed to make a hash code function for an array of doubles > (which is what seems the best way to me to implement HistoricalData)? It > would seem that since it can hold anywhere from 0 to as many as you like > elements, and each element can be any double value, that it would be > impossible to create a distinct integer hashcode for each possibility. A hashCode method doesn't have to give a distinct integer for each argument; it only has to return the same integer for two arguments, x and y, such that x.equals(y). Of course, it's better if hashCode returns different integers for different arguments, but by the pigeon-hole principle it will have to return the same result for distinct arguments if there are more potential arguments of a type than there are integers. BTW, I don't agree that an array of doubles is the best way to implement HistoricalData. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 --------------------------------------------------- From leavens@cs.iastate.edu Sun Apr 13 01:22:28 2003 Date: Sun, 13 Apr 2003 01:20:18 -0500 (CDT) From: Gary T. Leavens To: kwendzel@iastate.edu Cc: Staff for Com S 362 Subject: Re: CS 362: Help with Assignment 9 Hi Kevin, On Sat, 12 Apr 2003 kwendzel@iastate.edu wrote: > I get errors whenever I try to call assertEquals when I test the average and > max functions. I'm almost positive the problem is that these functions throw > exceptions, but when I try and catch the exceptions, all the assertEquals > functions still have errors. Here is what I'm trying to do: > > public void testMax() { > try { > HistoricalData data = new HistoricalData(); > assertEquals(Double.NaN, data.max()); > data.add(-2.5); > assertEquals(-2.5, data.max()); ... > } catch (...) { ... > } > } > > and I don't know what's wrong with it. Are you getting compile errors? You should be. The JUnit methods for assertEquals that take doubles all take 3 arguments: the expected value, the expression to be tested, and a tolerance (delta). Note also that Double.NaN has very strange behavior with respect to == in Java. If you are getting assertion failures on assertEquals(Double.NaN, data.max()); then that is the probelm. Better to test with: assertTrue(Double.isNaN(data.max()); > Also, I am seeing that you are right about trying to implement this with an > array. Right now I am trying to get the Vector class to work, but I want to > store doubles in it but the function addElement won't accept any argument > except of type object, and I can't get it to typecast either seeing as I can't > even declare a varaible of type object. How can I get around these problems? To store a double in a Vector, you need to use a vector of Double objects. See the class java.lang.Double. Also a vector doesn't satisfy the part of the assignment that says you should use the minimum possible space... -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ---------------------------------------------- From leavens@cs.iastate.edu Sun Apr 13 01:22:45 2003 Date: Sun, 13 Apr 2003 01:22:11 -0500 (CDT) From: Gary T. Leavens To: An HoGeun Cc: Staff for Com S 362 Subject: Re: questions for cs362 hw#9 Hi An Honguen, On Sun, 13 Apr 2003, An HoGeun wrote: > I don't know how to test a method which does not return any values with Junit. > > For example, in hw9, how can we test "add" method of HistoricalData ? > > Should we use another method of HistoricalData like "size" or "equals" > > to test "add" method ? Yes. In my testAdd method, I used "size", "average" and "max". -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 From leavens@cs.iastate.edu Sun Apr 13 20:57:17 2003 Date: Sun, 13 Apr 2003 20:56:57 -0500 (CDT) From: Gary T. Leavens To: David Gillingham Cc: cs362s@cs.iastate.edu Subject: Re: [CS362 - Hw9] Requirement Question Hi David, On Sun, 13 Apr 2003, David Gillingham wrote: > In the homework, it is stipulated that we create the class to use "minimum > possible amount of run-time space for objects of type HistoricalData". To > accomplish this, are we expected to create our own wrapper class to store > the data, or should we use one of the built-in Java classes? I believe it can be done without creating your own wrapper class. In my code for HistoricalData, I only used Java's built-in value types, and didn't even use any reference types. That is, the types of the fields I declared were not even classes or interfaces. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 --------------------------------------- From leavens@cs.iastate.edu Sun Apr 13 22:54:16 2003 Date: Sun, 13 Apr 2003 22:53:59 -0500 (CDT) From: Gary T. Leavens To: David Gillingham Cc: Staff for Com S 362 Subject: RE: [CS362 - Hw9] Requirement Question Hi David, On Sun, 13 Apr 2003, David Gillingham wrote: > I suppose then, that I don't quite understand exactly how to accomplish this > or what you're expecting from us as far as the efficiency thing goes. Given > you previous responses and the hint you put in the assignment outline, none > of this is clicking. Could you perhaps be a little clearer on how to do > this without Vectors or arrays? You need to be able to compute: the number of measurements, the average of all measurements, and the maximum measurement. Think about what information is needed to compute the average. How is it calculated? Just store that. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------------------------- From leavens@cs.iastate.edu Mon Apr 14 18:09:55 2003 Date: Mon, 14 Apr 2003 18:02:02 -0500 (CDT) From: Gary T. Leavens To: kwendzel@iastate.edu Cc: Com S 362 students and staff -- Brian Thola , Yoonsik Cheon , com_s_362@cs.iastate.edu, David Avila , Derek James Light , Gaurav Dhiman , Kevin J Gaul , Les Miller , Olatunde Olatunji , Ritesh Desai , Tongjie Chen Subject: COMS 362: Re: CS 362: Another Homework Question on HW9 Hi Kevin, On Mon, 14 Apr 2003 kwendzel@iastate.edu wrote: > The equals method of Historical data returns "true if the argument is a > HistoricalData object with the same size, minimum, maximum, and average." How > do I test for the minimum if there is no method that retrieves the minimum? > Am I allowed to add new methods to the class? Oops, the "minimum" in the documentation comment for equals is a hold-over from an earlier version of the problem. Please delete that. My mistake. You only need equals to test to see if the other object is a HistoricalData object with the same size, maximum, and average. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ---------------------------------------- From leavens@cs.iastate.edu Mon Apr 14 21:42:42 2003 Date: Mon, 14 Apr 2003 21:39:11 -0500 (CDT) From: Gary T. Leavens To: Joe Lahart Cc: cs362s@cs.iastate.edu Subject: Re: hw9 Hi Joe, On Mon, 14 Apr 2003, Joe Lahart wrote: > To make sure I understand what to hand in...You want two copies of our code, > one without JML and one with JML? Yes, two copies, one without JML for part (b) and one with for part (d). -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ---------------------------------------------- From leavens@cs.iastate.edu Mon Apr 14 21:42:57 2003 Date: Mon, 14 Apr 2003 21:42:31 -0500 (CDT) From: Gary T. Leavens To: David A. Avila Cc: Staff for Com S 362 Subject: Re: hw 9 question Hi David, On Mon, 14 Apr 2003, David A. Avila wrote: > How do we test for the clone method. I cant seem to get how do we accesed > the clone made by the function To test it you should see that it's not null, and call some of the methods on the returned object. To call the methods you'll have to downcase it. For example: HistoricalData c = (HistoricalData) o.clone(); If you don't downcast it, Java treats it as an Object, so you can't call any of HistoricalData's methods (you get type errors). If this isn't what you mean, let me know. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------------------------ From leavens@cs.iastate.edu Mon Apr 14 22:56:09 2003 Date: Mon, 14 Apr 2003 22:53:51 -0500 (CDT) From: Gary T. Leavens To: Carl Cc: Staff for Com S 362 Subject: Re: CS 362:Homework Question on HW9 Hi Carl, On Mon, 14 Apr 2003, Carl wrote: > In your homework description you say that a subclass of TestCase should have a > constructor: "public HistoricalDataTest(String name) {super(name);}" I am a > little confused by this. What is the purpose of the subclass? And What is > meant by "subclass?" Any help would be apreciated In Java if you write class A extends B then A is a subclass of B and B is a superclass of A. See your Java book for more details. The purpose of the subclassing in this case is to make your tests fit into the JUnit framework; that is so you can run tests. Every test case class needs such a constructor as the one shown, because if you read the javadocs for junit.framework.TestCase, you aren't supposed to call teh default (no argument) constructor, and every subclass constructor has to call some constructor of its superclass. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 --------------------------------------------------------- From leavens@cs.iastate.edu Mon Apr 14 22:56:30 2003 Date: Mon, 14 Apr 2003 22:55:52 -0500 (CDT) From: Gary T. Leavens To: David Gillingham Cc: cs362s@cs.iastate.edu Subject: Re: [362 HW9] JML Syntax question Hi David, On Mon, 14 Apr 2003, David Gillingham wrote: > I have some questions about JML syntax regarding homework 9. In the add all > function, I am trying to describe how the average of the HistoricalData will > be recomputed. And I came up with this JML snippet > (\sum int i; 0 <= i && i < measurements.length; measurements[i]) > I am trying to use this to describe computing the sum of all the elements in > the measurements array. I am making no qualifications about what this sum > equals, just that I will be using this as one of the terms in recalculating > the HistoricalData's average. Is the proper syntax? Yes. > Similarly, is it correct to use a similar expression to show the maximum of > the values in the array? Such as this-- > (\max int i; 0 <= i && i < measurements.length; measurements[i]) > Is this a proper way to describe the maximum value from the array, which > will be checked against the old maximum of the data? Yes, that looks fine to me. (Also if you run jmlc on your file, it will tell you if you are using the right syntax or not.) -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------------------- From leavens@cs.iastate.edu Mon Apr 14 23:36:17 2003 Date: Mon, 14 Apr 2003 23:34:02 -0500 (CDT) From: Gary T. Leavens To: Joe Lahart Cc: cs362s@cs.iastate.edu Subject: Re: hw9 Hi Joe, On Mon, 14 Apr 2003, Joe Lahart wrote: > I'm having a hard time understanding when to make a method use the JML /*@ > pure @*/ notation. For the most part does it just mean that the method does > not modify any member variables? Or can there be more to it than that? It's when the method should not (in any reasonable implementation) have any side effects that are visible to clients. This certainly includes assigning to member variables, but it also prohibits I/O and assignment to fields of other objects. See http://www.cs.iastate.edu/~leavens/JML/prelimdesign/prelimdesign_2.html#SEC33 for details. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 -------------------------------------------------------- From leavens@cs.iastate.edu Mon Apr 14 23:36:35 2003 Date: Mon, 14 Apr 2003 23:36:01 -0500 (CDT) From: Gary T. Leavens To: David A. Avila Cc: Staff for Com S 362 Subject: Re: question Hi David, On Mon, 14 Apr 2003, David A. Avila wrote: > Do we need to use assertEquals in our test units. I am currently using if and > else statemnets. Is that alright?? You have to do something to tell the JUnit framework that a test succeeds or fails. You can do that using if-then-else if you explicitly call the "fail" method on all the failed branches. But usually it's easier to use the JUnit methods assertEquals, assertTrue, etc. to call "fail" implicitly. So the answer is probably "no, it's not all right". Does that help? -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 --------------------------------------------------------- From leavens@cs.iastate.edu Tue Apr 15 08:03:49 2003 Date: Tue, 15 Apr 2003 08:00:23 -0500 (CDT) From: Gary T. Leavens To: David A. Avila Cc: Staff for Com S 362 Subject: Re: hw question David, On Tue, 15 Apr 2003, David A. Avila wrote: > Professor, > > I am having trouble with the assertionEquals and assertionTrue, it gives me > errors. I read in Q & A that these need three inputs but what exactly is the > third input, an integer?? or something else?? The methods are named assertEquals and assertTrue. The assertTrue method takes a boolean as an argument. The third argument for assertEquals when the first two arguments are type double is also type double, and it's the tolerance for comparing the first two. See the JUnit javadocs, either in your local copy or from: http://www.junit.org/junit/javadoc/3.8.1/index.htm More specifically look at: http://www.junit.org/junit/javadoc/3.8.1/index.htm/overview-summary.html/junit/framework/junit/framework/Assert.html/Assert.html for documentation on junit.framework.Assert, which is a superclass of TestCase. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ---------------------------------------- From leavens@cs.iastate.edu Tue Apr 15 18:13:08 2003 Date: Tue, 15 Apr 2003 18:11:25 -0500 (CDT) From: Gary T. Leavens To: kwendzel@iastate.edu Cc: Staff for Com S 362 Subject: Re: CS 362: Help with compiling JML Hi Kevin, On Tue, 15 Apr 2003 kwendzel@iastate.edu wrote: > I am having trouble compiling with JML and was wondering if you could help me. > > First I tried to run "javac HistoricalDataTest.java" from the command prompt > in Windows XP, but that gave me a whole bunch of errors that basically said > that it didn't know what the assertEquals function was. So I just decided to > compile it from Eclipse. Sounds like your CLASSPATH must be wrong at the command prompt. You need to have the JUnit jar file in your CLASSPATH, for which you need to have JUnit installed. > I then tried to run "jmlc -p HistoricalData.java". No matter what I do, I get > the error "'java' is not recognized as an internal or external command, > operable program or batch file." I have tried editing jmlc.bat so the > CLASSPATH would include the directory where java.exe is installed and I also > tried copying java.exe into my C:\JML\bin folder, both of which had no luck. > Do you know what's wrong. JML is installed in C:\JML just as the program > asks. Thanks for your help. It seems that you don't have the java virtual machine (i.e., the "java" command) installed and on your PATH. Try running java -version from a command prompt. If that doesn't work, this is your problem. To fix it, make sure that you have installed JDK 1.4.1. Then in XP, open up the control panel and go to performance and maintenance, then click on System, and on the Advanced tab in the popup. Then click on Environment Variables (bottom left) and make sure that the bin directory for JDK 1.4.1 is installed is in your Path under "System Variables". -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 -------------------------------------------- From leavens@cs.iastate.edu Tue Apr 15 22:51:04 2003 Date: Tue, 15 Apr 2003 22:47:52 -0500 (CDT) From: Gary T. Leavens To: Emily Ericson Cc: cs362s@cs.iastate.edu Subject: Re: Hw9 Hi Emily, On Tue, 15 Apr 2003, Emily Ericson wrote: > For part (a) of the homework it says to print a copy of our test code and a > copy of the output. Does the output refer to the JUnit list of failures and > errors and if so how do I print that panel? I'm not sure how to get the output from Eclipse, although I guess you can make a screen shot. But the best thing to do is to use a command-line interface (a DOS window or cygwin), and get the output from the JUnit text interface into a file. $ java TestHistoricalData >TestHistoricalData.out or if you don't have a main routine, then $ java junit.textui.TestRunner TestHistoricalData >TestHistoricalData.out Does that help? -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 --------------------------------- From leavens@cs.iastate.edu Wed Apr 16 00:07:43 2003 Date: Wed, 16 Apr 2003 00:07:26 -0500 (CDT) From: Gary T. Leavens To: Emily Ericson Cc: Staff for Com S 362 Subject: Re: Hw9 Hi Emily, On Tue, 15 Apr 2003, Emily Ericson wrote: > I'm trying to get the output of my test class to print and I keep getting a > NoClassDefFound error. Is this a problem with my classpath? And if so what > can I do to fix it. The file runs in eclipse what do I need to change when > using the command prompt? Yes, it's probably a CLASSPATH problem. Did you download and install JUnit 3.8.1? Is the jar for JUnit 3.8.1 on your CLASSPATH? -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ---------------------------------------------- From leavens@cs.iastate.edu Sun Apr 20 20:00:05 2003 Date: Sun, 20 Apr 2003 19:59:05 -0500 (CDT) From: Gary T. Leavens To: kwendzel@iastate.edu Cc: Staff for Com S 362 Subject: Re: COMS 362: Solutions to practice test for exam3 for 362 Hi Kevin, Yes, the link is the old test without the answers. I had an *attachment* in the email that I sent you with the answers to the old test. Sorry for the confusion. On Sun, 20 Apr 2003 kwendzel@iastate.edu wrote: > I don't know if I'm doing something wrong or looking in the wrong place or > what, but I'm not seeing any answers in the PDF pointed to by the link. It > just looks like the old test without the answers to me. Am I doing something > wrong? Thanks for your help. > > Kevin Wendzel > kwendzel@iastate.edu > > > > Hi all, > > > > As promised, here are my solutions to last year's exam 3, which I > > passed out in class as a practice test. If you want to try this as in > > the exam, try to do the probelms first, and then look at each answer > > and use that for the next one. The exam from last Fall is in: > > > > http://www.cs.iastate.edu/~leavens/ComS362/old-exams/Fall2002/exam3- > analysis-design.pdf > > > > > in case you weren't in class... -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580