3 minute read

If you have ever tried writing any non trivial tests, mocks should not be a stranger to you. But what about some other “mock” like objects like stubs, spies and such? How are they different from each other? In this blog post, I will explain it as simple and easy to remember as possible. Everything is a test double. Test double is just a general name for all mock like objects.

1 minute read

Code kata

Problem The elevator can be on first floor or second floor The elevator can be either openned or closed. The elevator can go up or down. But when it goes up or down, the door has to be closed. The door can open or close, but it cannot open when it is already openned or close when it is already closed. Write a function that takes a list of actions with :done indicating the end, and return if this sequence is legal or not.

2 minute read

What this recur and tail calls optimization is all about in Clojure? This blog post is trying to give a short yet easy to remember explanation. Before explaining anything, let’s look at how we can implement + using recursion. This is actually an interesting task, implement our +, since most of the time + is a built-in function. So to make things a bit more clear, let’s assume that our computer is drunk and forgets about how to do +, but it still remembers how to increment and decrement by 1.

1 minute read

Code kata

Problem Implement a unit converter that uses the given the following metric (def metric {:meter 1 :km 1000 :cm 1/100 :mm [1/10 :cm]}) The converter should anwser questions like: How many meters are there in 10 km and 20 cm? Solution (defn convert [context descriptor] (reduce (fn [result [mag unit]] (let [val (metric unit)] (if (vector? val) (+ result (* mag (convert context val))) (+ result (* mag val))))) 0 (partition 2 descriptor))) (convert metric [1 :meter]) (convert metric [3 :km 10 :meter])