~willvaughn/kata

bec2e701d84ca2de44b867c45e0480341c1f7441 — William Vaughn 1 year, 5 months ago a33b6cc
exercism download interest is interesting
A exercism/clojure/interest-is-interesting/.exercism/config.json => exercism/clojure/interest-is-interesting/.exercism/config.json +20 -0
@@ 0,0 1,20 @@
{
  "authors": [
    "porkostomus"
  ],
  "files": {
    "solution": [
      "src/interest_is_interesting.clj"
    ],
    "test": [
      "test/interest_is_interesting_test.clj"
    ],
    "exemplar": [
      ".meta/exemplar.clj"
    ]
  },
  "forked_from": [
    "csharp/floating-point-numbers"
  ],
  "blurb": "Learn about floating-point numbers by calculating interest for savings accounts"
}

A exercism/clojure/interest-is-interesting/.exercism/metadata.json => exercism/clojure/interest-is-interesting/.exercism/metadata.json +1 -0
@@ 0,0 1,1 @@
{"track":"clojure","exercise":"interest-is-interesting","id":"75c7a40d81954d528cf1aad410d77c27","url":"https://exercism.org/tracks/clojure/exercises/interest-is-interesting","handle":"willvaughn","is_requester":true,"auto_approve":false}
\ No newline at end of file

A exercism/clojure/interest-is-interesting/HELP.md => exercism/clojure/interest-is-interesting/HELP.md +75 -0
@@ 0,0 1,75 @@
# Help

## Running the tests

## Clojure CLI

The Clojure exercises on Exercism ship with a `deps.edn` file with a `:test` alias to invoke the [cognitect-labs test-runner](https://github.com/cognitect-labs/test-runner):

``` bash
$ clj -X:test
```

## Leiningen

Leiningen can also be used to run the exercise's test by running the following command from the exercise's directory:

```bash
lein test
```

## REPL

To use the REPL to run the exercise's test, run the following command from the exercise's directory:

```bash
$ clj
```

-or-

```bash
$ lein repl
```

Then `require` the exercise's test namespace and the Clojure test namespace):

```clojure
;; replace <exercise> with the exercise's name
=> (require '<exercise>-test)
```

Then call `run-tests` on `<exercise>-test`:

```clojure
;; replace <exercise> with the exercise's name
=> (clojure.test/run-tests '<exercise>-test)
```

## Submitting your solution

You can submit your solution using the `exercism submit src/interest_is_interesting.clj` command.
This command will upload your solution to the Exercism website and print the solution page's URL.

It's possible to submit an incomplete solution which allows you to:

- See how others have completed the exercise
- Request help from a mentor

## Need to get help?

If you'd like help solving the exercise, check the following pages:

- The [Clojure track's documentation](https://exercism.org/docs/tracks/clojure)
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)

Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.

To get help if you're having trouble, you can use one of the following resources:

- [Ask Clojure](https://ask.clojure.org/) Official forum for Clojure Q & A.
- [ClojureDocs](https://clojuredocs.org) A repository of language references and examples by function or keyword.
- [/r/clojure](https://www.reddit.com/r/clojure) is the Clojure subreddit.
- [StackOverflow](http://stackoverflow.com/questions/tagged/clojure) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.
- [Clojureverse](https://clojureverse.org/) Friendly and inclusive Clojure(Script) Community
\ No newline at end of file

A exercism/clojure/interest-is-interesting/HINTS.md => exercism/clojure/interest-is-interesting/HINTS.md +18 -0
@@ 0,0 1,18 @@
# Hints

## Calculate the interest rate

- You can refer back to the [conditionals][conditionals] concept if you need to remember how to return values based on an input value.

## Calculate the annual balance update

- The [`bigdec`][bigdec] function can be used to coerce a number to a [BigDecimal][bigdecimal].

## Calculate how much money to donate

- The [`int`][int] function can be used to coerce a number to an integer.

[bigdec]: https://clojuredocs.org/clojure.core/bigdec
[bigdecimal]: https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html
[conditionals]: https://exercism.org/tracks/clojure/concepts/conditionals
[int]: https://clojuredocs.org/clojure.core/int
\ No newline at end of file

A exercism/clojure/interest-is-interesting/README.md => exercism/clojure/interest-is-interesting/README.md +71 -0
@@ 0,0 1,71 @@
# Interest is Interesting

Welcome to Interest is Interesting on Exercism's Clojure Track.
If you need help running the tests or submitting your code, check out `HELP.md`.
If you get stuck on the exercise, check out `HINTS.md`, but try and solve it without using those first :)

## Introduction

A floating-point number is a number with zero or more digits behind the decimal separator. Examples are `-2.4`, `0.1`, `3.14`, `16.984025` and `1024.0`.

Different floating-point types can store different numbers of digits after the digit separator - this is referred to as its precision. This means that trying to store PI in a `single` will only store the first 6 to 9 digits (with the last digit being rounded).

Floating point numbers in Clojure are read as Doubles; with M suffix they are read as BigDecimals.

- `Double`: 8 bytes (~15-17 digits precision). This is the most common type. Written as `2.45`.
- `BigDecimal`: Arbitrary precision integer unscaled value and a 32-bit integer scale. Written as `2.45M`.

## Instructions

In this exercise you'll be working with savings accounts. Each year, the balance of your savings account is updated based on its interest rate. The interest rate your bank gives you depends on the amount of money in your account (its balance):

- -3.213% for a negative balance.
- 0.5% for a positive balance less than `1000` dollars.
- 1.621% for a positive balance greater or equal than `1000` dollars and less than `5000` dollars.
- 2.475% for a positive balance greater or equal than `5000` dollars.

Each year, **before** the balance of your savings account is updated, the government allows you to donate a percentage of your money to charity, tax free. Because you're a nice person, if your balance is positive at the end of the year, you donate twice this amount to charities, rounded down to the nearest whole dollar.

You have three tasks, each of which will deal with your balance and its interest rate.

## 1. Calculate the interest rate

Implement the `interest-rate` function to calculate the interest rate based on the specified balance:

```clojure
(interest-rate 200.75M)
;;=> 0.5
```

Note that the value returned is a `Double`.

## 2. Calculate the annual balance update

Implement the `annual-balance-update` function to calculate the annual balance update, taking into account the interest rate:

```clojure
(annual-balance-update 200.75M)
;;=> 201.75375M
```

Note that the value returned is a `BigDecimal`.

## 3. Calculate how much money to donate

Implement the `amount-to-donate` function to calculate how much money to donate to charities based on the balance and the tax-free percentage that the government allows:

```clojure
(def balance 550.5M)
(def tax-free-percentage 2.5)

(amount-to-donate balance tax-free-percentage)
;;=> 27
```

Note that the value returned is an `int`.

## Source

### Created by

- @porkostomus
\ No newline at end of file

A exercism/clojure/interest-is-interesting/deps.edn => exercism/clojure/interest-is-interesting/deps.edn +6 -0
@@ 0,0 1,6 @@
{:aliases {:test {:extra-paths ["test"]
                  :extra-deps {io.github.cognitect-labs/test-runner
                               {:git/url "https://github.com/cognitect-labs/test-runner.git"
                                :sha "705ad25bbf0228b1c38d0244a36001c2987d7337"}}
                  :main-opts ["-m" "cognitect.test-runner"]
                  :exec-fn cognitect.test-runner.api/test}}}
\ No newline at end of file

A exercism/clojure/interest-is-interesting/project.clj => exercism/clojure/interest-is-interesting/project.clj +4 -0
@@ 0,0 1,4 @@
(defproject interest-is-interesting "0.1.0-SNAPSHOT"
  :description "interest-is-interesting exercise."
  :url "https://github.com/exercism/clojure/tree/main/exercises/concept/interest-is-interesting"
  :dependencies [[org.clojure/clojure "1.10.0"]])
\ No newline at end of file

A exercism/clojure/interest-is-interesting/src/interest_is_interesting.clj => exercism/clojure/interest-is-interesting/src/interest_is_interesting.clj +16 -0
@@ 0,0 1,16 @@
(ns interest-is-interesting)

(defn interest-rate
  "TODO: add docstring"
  [balance]
  )

(defn annual-balance-update
  "TODO: add docstring"
  [balance]
  )

(defn amount-to-donate
  "TODO: add docstring"
  [balance tax-free-percentage]
  )
\ No newline at end of file

A exercism/clojure/interest-is-interesting/test/interest_is_interesting_test.clj => exercism/clojure/interest-is-interesting/test/interest_is_interesting_test.clj +84 -0
@@ 0,0 1,84 @@
(ns interest-is-interesting-test
  (:require [clojure.test :refer [deftest testing is]]
            interest-is-interesting))

(deftest minimal-first-interest-rate-test
  (is (= 0.5 (interest-is-interesting/interest-rate 0M))))

(deftest tiny-first-interest-rate-test
  (is (= 0.5 (interest-is-interesting/interest-rate 0.000001M))))

(deftest maximum-first-interest-rate-test
  (is (= 0.5 (interest-is-interesting/interest-rate 999.9999M))))

(deftest minimal-second-interest-rate-test
  (is (= 1.621 (interest-is-interesting/interest-rate 1000.0M))))

(deftest tiny-second-interest-rate-test
  (is (= 1.621 (interest-is-interesting/interest-rate 1000.0001M))))

(deftest maximum-second-interest-rate-test
  (is (= 1.621 (interest-is-interesting/interest-rate 4999.9990M))))

(deftest minimal-third-interest-rate-test
  (is (= 2.475 (interest-is-interesting/interest-rate 5000.0000M))))

(deftest tiny-third-interest-rate-test
  (is (= 2.475 (interest-is-interesting/interest-rate 5000.0001M))))

(deftest large-third-interest-rate-test
  (is (= 2.475 (interest-is-interesting/interest-rate 5639998.742909M))))

(deftest minimal-negative-interest-rate-test
  (is (= -3.213 (interest-is-interesting/interest-rate -0.000001M))))

(deftest small-negative-interest-rate-test
  (is (= -3.213 (interest-is-interesting/interest-rate -0.123M))))

(deftest regular-negative-interest-rate-test
  (is (= -3.213 (interest-is-interesting/interest-rate -300.0M))))

(deftest large-negative-interest-rate-test
  (is (= -3.213 (interest-is-interesting/interest-rate -152964.231M))))

(deftest annual-balance-update-empty-balance-test
  (is (= 0.0000M (interest-is-interesting/annual-balance-update 0.0M))))

(deftest annual-balance-update-small-positive-balance-test
  (is (= 0.000001005M (interest-is-interesting/annual-balance-update 0.000001M))))

(deftest annual-balance-update-average-positive-balance-test
  (is (= 1016.210000M (interest-is-interesting/annual-balance-update 1000.0M))))

(deftest annual-balance-update-large-positive-balance-test
  (is (= 1016.210101621M (interest-is-interesting/annual-balance-update 1000.0001M))))

(deftest annual-balance-update-huge-positive-balance-test
  (is (= 920352587.26744292868451875M (interest-is-interesting/annual-balance-update 898124017.826243404425M))))

(deftest annual-balance-update-small-negative-balance-test
  (is (= -0.12695199M (interest-is-interesting/annual-balance-update -0.123M))))

(deftest annual-balance-update-large-negative-balance-test
  (is (= -157878.97174203M (interest-is-interesting/annual-balance-update -152964.231M))))

(deftest amount-to-donate-empty-balance-test
  (is (= 0 (interest-is-interesting/amount-to-donate 0.0M 2.0))))

(deftest amount-to-donate-small-positive-balance-test
  (is (= 0 (interest-is-interesting/amount-to-donate 0.000001M 2.1))))

(deftest amount-to-donate-average-positive-balance-test
  (is (= 40 (interest-is-interesting/amount-to-donate 1000.0M 2.0))))

(deftest amount-to-donate-large-positive-balance-test
  (is (= 19 (interest-is-interesting/amount-to-donate 1000.0001M 0.99))))

(deftest amount-to-donate-huge-positive-balance-test
  (is (= 47600572 (interest-is-interesting/amount-to-donate 898124017.826243404425M 2.65))))

(deftest amount-to-donate-small-negative-balance-test
  (is (= 0 (interest-is-interesting/amount-to-donate -0.123M 3.33))))

(deftest amount-to-donate-large-negative-balance-test
  (is (= 0 (interest-is-interesting/amount-to-donate -152964.231M 5.4))))