Homework 22: Tests
Submit this homework using Gradescope. You can type up your answers, or write legibly and scan them. Do not attempt to submit a paper copy in class, as it will not be accepted.
Write JUnit-style test methods for each of the following (one method per test, please) (1 point each):
length()
is correct for empty stringslength()
is correct for non-empty stringstoUpperCase()
works correctlyindexOf(String str)
works correctly whenstr
is not foundindexOf(String str, int fromIndex)
works correctly whenstr
is located both before and afterfromIndex
(that is, setfromIndex
such that the index of the second occurrence ofstr
is what you expect to be found)
Use "yellow submarine yellow"
as the non-empty String
object in each relevant test, and "yellow"
as the substring (str
) to search for with indexOf
.