Вы находитесь на странице: 1из 6

CIS 120 HW02 FAQ

GENERAL
Q. What should I read for help on this homework assignment?
Q. Help! I cant compile! I cant run tests! I get a strange error message!
Q. Should we use functions previously made within the HW file as helper function
s for later questions?
Q. Do we have to make up extra tests for each problem? How much tests are normal
ly expected?
Q. I tried making an executable the way we learned but it is not showing up. Wha
t should I do?
Q. What do we do if a statement in match function crosses the 80 char limit for
the line?
Q. If I want to resubmit with better style, can I?
Q. How can I get a good style grade?
Q. Do we need to write comments for every function or only additional helper fun
ctions we ve written?
Q. Should comments be written on top of the function summarizing the entire code
or next to each part of the function explaining what each part does?
Q. The console says a function is unimplemented even though I just wrote it. Wha
t should I do?
Q. Can you give me tips on pattern matching?
Q. My functions have passed all the written test cases (as well as some I have w
ritten) for all the earlier steps. However, my final print out of the lesser and
greater ape trees are wrong. How do I debug?
Q. Can I write a test case that checks that certain inputs should fail?

HOMEWORK 2
Q. Do I need to write code for question_most_like_human or can I just hard-code th
e list?
Q. In problem 3, should all the requirements be satisfied with one function "aci
ds_of_helix" or can we write helper functions for this function?
Q. For problem 3, do we have to account for multiple amino acid chains in the sa
me helix?
Q. In problem 3, if one of the end acids is at the beginning of the list should
the rest of the codons be read?
Q. For problem 4, my tree is outputted as a mirror image of expected tree. Is th
at okay?
Q. Can we assume that acids_of_helix takes a helix that s at least a length of 3
?
Q. Is there a way in OCaml to check whether a value is a certain type? Such as s
aying, if lt = Leaf or if lt=Node?
Q. Why am I getting an error saying type tree has no Empty constructor?
Q. Does hamming distance need to account for the differences between a parent an
d its childs child?
Q. What should I do with gtest.ml?

GENERAL
Q. What should I read for help on this homework assignment?
1. Chapters 5, 6, and 7 of the lecture notes and the lecture slides.
Q. Help! I cant compile! I cant run tests! I get a strange error message!
1. See the project troubleshooting FAQ
Q. Should we use functions previously made within the HW file as helper function
s for later questions?
1. Absolutely otherwise some of the later problems would be a mess!
Q. Do we have to make up extra tests for each problem? How much tests are normal
ly expected?
1. Yes, we expect that you will add your own test cases to supplement ours. In l
ater homeworks, you will be responsible for unit testing your code without relyi
ng on any provided test cases.
There isn t really a specific answer to the question of how many test cases to w
rite. Generally the rule of thumb is "enough to cover all possible cases of inpu
t", so this may mean testing a range of structural variants (e.g. an empty list
case and a list with elements), varying numbers of inputs (e.g. null/missing/no
elements, a single element, a small set of elements, and a large set of elements
), and any corner cases that you come up with when first reading the problem (e.
g. particular errors or behavior that isn t immediately related to "standard" ca
ses).
Basically, only stop writing unit tests once you reach the point where you re re
asonably confident that your implementation is correct! Where exactly that point
lies is definitely not something that s immediately obvious, but that s why we
re having you practice--once you become familiar with how to unit-test effective
ly, you ll be able to judge when your tests are sufficient.
Q. I tried making an executable the way we learned but it is not showing up. Wha
t should I do?
1. Have you checked that your code is compiling? Eclipse won t update the .exe u
nless your changes compile, so if there are any red x s or underlines you should
fix those issues and it will hopefully (re)generate the executable. Restarting
eclipse and cleaning your project (project-> clean) can both help. If this does
not solve the problem, you may need to bring your computer to office hours.

Q. What do we do if a statement in match function crosses the 80 char limit for


the line?
1. The short answer is break the line into multiple shorter lines.
The long answer is, first, try to avoid having long lines at all. If an expressi
on is too long, consider using some variables to do preprocessing. If necessary,
break the line at the highest logical level.
Q. If I want to resubmit with better style, can I?
1. If you still have extra submissions remaining, you are highly encouraged to r
esubmit your code with better style. The last submission you make will be the on
e that is graded for style.
Q. How can I get a good style grade?
1. Your TA should give you style feedback from the first homework two days befor
e the homework is due. You should also look at the style guide to see what were l
ooking for.
Q. Do we need to write comments for every function or only additional helper fun
ctions we ve written?
1. You only need to comment additional helper functions that you add to clarify
what they are used for.
Q. Should comments be written on top of the function summarizing the entire code
or next to each part of the function explaining what each part does?
1. Preferably at the top of the code. And keep it very short! The only time you
should add comments inline with code is if it is some really cryptic calculation
that warrants explanation, otherwise it often detracts from general readability
.
Q. The console says a function is unimplemented even though I just wrote it. Wha
t should I do?
1. This is usually a sign that your code is not compiling. The executable will o

nly update when there are no errors in your code keeping your code from compilin
g. Find the red underlines, fix the errors, save the file, then run the executab
le again and see if this fixes the problem.

Q. Can you give me tips on pattern matching?


1. I ve noticed a lot of people are asking questions that have to do with patter
n matching and how to get the information you want out of a list. Pattern matchi
ng is a very useful feature of OCaml, and there are more ways to pattern match t
han the standard [] and hd::tl. For instance, say I wanted to return the last el
ement of an integer list. I could do this:
let rec foo (l : int list) : int =
begin match l with
| [] -> failwith "empty list"
| [x] -> x
| hd::tl -> foo tl
end
Say I wanted to return the the sum of the last two elements of an integer list.
I could do this:
let rec foo (l : int list) : int =
begin match l with
| fst::snd::[] -> fst + snd
| hd::tl -> foo tl
| _ -> failwith "list has less than two elements"
end
The underscore pattern matches against any pattern. Therefore, it s usually used
as the last pattern to match against, since it works as a catch all. However, i
t can also be nested inside of a more complex pattern. Consider a function that
returns the length of a list:
let rec length (l : int list) : int =
begin match l with
| _::tl -> 1 + length tl
| _ -> 0
end

The head element of the list is irrelevant, as long as there is a head element.
Hence the underscore in the first pattern. The second underscore catches all oth
er cases that get past the first pattern. Which is only the empty list.
Section 4.2 in the lecture notes goes more in depth with this, and also talks ab
out tuples, which will give you even more ways to pattern match, and are useful
in situations where you have two things you want to examine, like two lists.

Q. My functions have passed all the written test cases (as well as some I have w
ritten) for all the earlier steps. However, my final print out of the lesser and
greater ape trees are wrong. How do I debug?
1. Go back and make sure the test cases for all your functions are actually exha
ustive. It sounds like you missed a case.
Q. Can I write a test case that checks that certain inputs should fail?
1. Yes. See run_failing_test in assert.

HOMEWORK 2
Q. Do I need to write code for question_most_like_human or can I just hard-code th
e list?
1. You can just hard-code the list.
Q. In problem 3, should all the requirements be satisfied with one function "aci
ds_of_helix" or can we write helper functions for this function?
1. You re allowed to write helper functionsyou ll probably need one.
Q. For problem 3, do we have to account for multiple amino acid chains in the sa
me helix?
1. You only need to find one (the first) amino acid chain in the helix.
Q. In problem 3, if one of the end acids is at the beginning of the list should
the rest of the codons be read?
1. Assuming an END codon occurs within the acid chain, then no, you re done with
that list. But if the sequence that forms an END codon appears before the start

codon ([T; A; C]) then you should keep going.


Q. For problem 4, my tree is outputted as a mirror image of expected tree. Is th
at okay?
1. Yes. For these trees the left and right subtrees are interchangeable.
Q. Can we assume that acids_of_helix takes a helix that s at least a length of 3
?
1. Dont make that assumption. Remember that until you can ignore acids that occur
before (or without) the sequence [T; A; C].

Q. Is there a way in OCaml to check whether a value is a certain type? Such as s


aying, if lt = Leaf or if lt=Node?
1. You should use a pattern match to match the type. If statements wont work with
tests like that.
Q. Why am I getting an error saying type tree has no Empty constructor?
1. Take a closer look at the type defined in the homework. Its different than the
one used in the lectures on binary trees.
Q. Does hamming distance need to account for the differences between a parent an
d its childs child?
1. No. You only ever care about direct parent-child hamming distances.
Q: What should I do with gtest.ml?
1. Use gtest.ml to test that your OCaml graphics are working. To do this right c
lick on your Homework02 root file, click Properties, and click OCaml Build Flags
. Add graphics.cma and apply the changes, then go to OCaml Project to make gtest e
xecutable.
When you run the gtest executable a window should appear with a camel drawn in i
t. We are testing everyones graphics now because it is important for later homewo
rks and has been problematic for students in the past. See a TA if no camel appe
ars.

Вам также может понравиться