Skip to content

Commit

Permalink
Update 4-conditionals-testing.qmd
Browse files Browse the repository at this point in the history
  • Loading branch information
jhelvy committed Feb 8, 2024
1 parent 31ad317 commit 46bc0ca
Showing 1 changed file with 70 additions and 1 deletion.
71 changes: 70 additions & 1 deletion hw/4-conditionals-testing.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,73 @@ params:
> - To practice computational problem solving.
---

Coming soon!
```{r child = here::here("fragments", "hw.qmd")}
```

### Readings

The readings from the last week will serve as a helpful reference as you complete this assignment. You can review them here:

<blockquote class="blockquote">

```{r}
#| echo: false
#| message: false
#| results: asis
htmltools::HTML(readings_current)
```

</blockquote>

> ### Using the [autograder](../autograder.html)
>
> - You can check your solutions to problems 2 - 7 by logging into the [autograder](../autograder.html) and uploading your `hw4.R` file.
> - **The file must be named `hw4.R` or it won't work.**
> - Your user name is your netID, and your password is inside the `readme.txt` file in the Box folder I shared with you.
### 1) Staying organized [SOLO, 5%]

Download and use [this template](templates/hw4.zip) for your assignment. Inside the "hw4" folder, open and edit the R script called "hw4.R" and fill out your name, Net ID, and the names of anyone you worked with on this assignment.

> ### **Writing test functions**
>
> For each of the following functions, write a test function first, and then write the function. **Your test functions will count for half of the available credit for each problem**. Think carefully about the test cases to include in your test functions.
### 2) `guessAnimal(hasFourLegs, climbsTrees)` [SOLO, 10%]

Write the function `guessAnimal(hasFourLegs, climbsTrees)` that returns a statement guessing an animal based on whether it has four legs and whether it climbs trees. Here is the expected behavior:

<div style="width:500px">
`hasFourLegs` | `climbsTrees` | statement
--------------|---------------|-------------
`TRUE` | `TRUE` | "It's probably a cat"
`TRUE` | `FALSE` | "It's probably a dog"
`FALSE` | `TRUE` | "It's probably a snake"
`FALSE` | `FALSE` | "Hmm, I'm not sure"
</div>

### 3) `isPositiveMultipleOf4Or7(n)` [SOLO, 15%]

Write the function `isPositiveMultipleOf4Or7(n)` that returns `TRUE` if `n` is a positive multiple of 4 or 7 and `FALSE` otherwise. Note than `n` could be any data type.

### 4) `isEvenPositiveInt(x)` [COLLABORATIVE, 20%]

Given an arbitrary value `x`, return `TRUE` if it is an integer, and it is positive, and it is even (all 3 must be true), or `FALSE` otherwise. If the value `x` is not an integer, the function should return `FALSE` rather than error. So, `isEvenPositiveInt("yikes!")` returns `FALSE`, and `isEvenPositiveInt(123456)` returns `TRUE`.

### 5) `isLeapYear(year)` [SOLO, 20%]

Write the function `isLeapYear(year)` that returns `TRUE` if `year` is a [leap year](https://www.mathsisfun.com/leap-years.html) and `FALSE` otherwise. Assume that `year` is a positive integer.

### 6) `getTheCents(n)` [COLLABORATIVE, 20%]

Write the function `getTheCents(n)` which takes a value `n` that represents a payment in US dollars and returns the number of cents in the payment. For example, if `n` is `2.45`, the function should return `45`. If `n` is an integer, the function should return `0`, as it has `0` cents; if it isn't a number, it should return `NULL`, because a non-number payment make no cents (ha!). If the payment has partial cents (for example, `3.953`), it should be rounded to the nearest cent (in this case, `95` cents).

### 7) Read and reflect [SOLO, 10%]

```{r child = here::here("fragments", "reflection.qmd")}
```

### Submit

{{< var hw_submit >}}

0 comments on commit 46bc0ca

Please sign in to comment.