- We're more interested in the process than in the final result.
- You are free to use anything you use in your daily work, including websites like Google or StackOverflow.
- You can use any language or tool you want, but we recommend that you use the language you feel most comfortable with and keep it super simple. You don't need a database or framework, a simple command line script that computes the values and prints them to the console is just fine for us. You can even hard code those invoices and the credit limit in the script to skip the JSON parsing.
- First make your code work, but afterwards take the time to make it nice. We would like to see maintainable & readable code. Simple scripts should have nice code, too. Please use features like classes, methods or functions!
BillFront finances invoices of its customers by paying out the invoice amount before it is collected. These invoices will be paid back by the customer of our customer, who we call a debtor.
For our tasks, we'll be using the following data:
The credit limit is the maximum amount the customer can get from BillFront.
Please write a script that given the invoices and the credit limit above computes the following values.
-
Financed amount, which would be:
40000
-
Financed amount of each invoice (A hash/map of invoice number to financed amount). A possible result is:
{ "inv-kola1": 16000, "inv-burger1": 15000, "inv-kola2": 9000, "inv-burrito1": 0, "inv-burger2": 0 }
-
Remaining customer credit:
0
As mentioned, you can use any language and framework you like, but if you want to use Ruby or Clojure, here's a stub to get you started. Feel free to change any part, including the tests!
# Start your implementation here:
# class FinancingCalculator
# # ..
# end
RSpec.describe "Invoice financing calculation" do
subject { raise NotImplementedError }
let(:invoices) do
[
{
debtor: "fritz-kola",
number: "inv-kola1",
amount: 16_000
},
{
debtor: "Tommi's Burger Joint",
number: "inv-burger1",
amount: 15_000
},
{
debtor: "fritz-kola",
number: "inv-kola2",
amount: 14_000
},
{
debtor: "Dolores",
number: "inv-burrito1",
amount: 15_000
},
{
debtor: "Tommi's Burger Joint",
number: "inv-burger2",
amount: 2000
}
]
end
let(:credit_limit) { 40_000 }
describe "financed amount" do
it "returns 40000" do
expect(raise NotImplementedError).to eq(40_000)
end
end
describe "financed invoice amount" do
it "returns a valid result" do
# NOTE: There are other valid solutions, if your implementation returns a
# different valid one, feel free to change this
expect(raise NotImplementedError).to eq(
"inv-kola1" => 16_000,
"inv-burger1" => 15_000,
"inv-kola2" => 9000,
"inv-burrito1" => 0,
"inv-burger2" => 0
)
end
end
describe "remaining credit" do
it "returns 0" do
expect(raise NotImplementedError).to eq(0)
end
end
end
You can run it like this:
gem install rspec # unless installed already
rspec calculator.rb # <- your file
(ns take-home.core
(:require [clojure.test :refer :all]))
;; Start your implementation here:
;; (defn finance-invoices []
;; ;; ...
;; )
(deftest finance-invoices-test
(let [invoices [{:debtor "fritz-kola"
:number "inv-kola1"
:amount 16000}
{:debtor "Tommi's Burger Joint"
:number "inv-burger1"
:amount 15000}
{:debtor "fritz-kola"
:number "inv-kola2"
:amount 14000}
{:debtor "Dolores"
:number "inv-burrito1"
:amount 15000}
{:debtor "Tommi's Burger Joint"
:number "inv-burger2"
:amount 2000}]
credit-limit 40000]
(testing "financed amount"
(is (= 40000 (throw (RuntimeException. "Implement me")))))
(testing "financed invoice amount"
;; NOTE: There are other valid solutions, if your implementation returns a
;; different valid one, feel free to change this
(is (= {"inv-kola1" 16000
"inv-burger1" 15000
"inv-kola2" 9000
"inv-burrito1" 0
"inv-burger2" 0}
(throw (RuntimeException. "Implement me")))))
(testing "remaining credit"
(is (= 0 (throw (RuntimeException. "Implement me")))))))
(run-tests)
If you create this simple project.clj
(defproject take-home "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.10.0"]]
:plugins [[lein-exec "0.3.7"]])
Then you could run it like this:
lein exec take_home.clj
# or with docker:
docker run -v `pwd`:`pwd` -w `pwd` clojure:alpine lein exec take_home.clj