Skip to main content

Posts

Showing posts from October, 2015

GeeCON programming contest answers

During this year's GeeCON and GeeCON Prague my company 4FinanceIT was giving away some gifts for people who correctly answered a couple of programming questions. Quite a few people asked about correct answers. Since I happened to write these tasks along with sample answers, let's share them publicly then:
1. Which of the following will not work as expected in multi-threaded environment (choose one)? new LongAccumulator(Math::min, Integer.MAX_VALUE); //a) new LongAccumulator(Math::max, Integer.MIN_VALUE); //b) new LongAccumulator(Math::addExact, 0); //c) new LongAccumulator(Math::subtractExact, 0) //d) Answer d) - according to JavaDoc: this class is only applicable to functions for which the order of accumulation does not matter Let's say you are accumulating 1 and 2. The result can be 0 - 1 - 2 but also (0 - 1) - (0 - 2) or (0 - 2) - (0 - 1).
See also: How LongAccumulator and DoubleAccumulator classes work?
2. Implement the following function:static &…

Spock VW: writing custom Spock framework extensions

Spock framework has multiple built-in extensions that support many core features like @Ignore and @Timeout annotations. But more importantly developers are encouraged to write their own extensions. For example SpringExtension nicely integrates Spock with Spring framework. Writing custom extensions is not very well documented. In this article we will write very simple extension. It is not a comprehensive guide but just a funny showcase.

Introducing Spock VW extension In some engineering branches[1] rigorous tests must pass only when external audit is looking. In programming this would be a continuous integration server. Spock VW extension makes sure all tests pass on CI server, even if they fail on developers machine or on production. The idea is heavily inspired by phpunit-vw. Let's take this simple, completely made up test that can't possibly succeed:

@Unroll class EmissionsSpec extends Specification { def 'nitrogen oxide emission (#emission) in #model must not exceed…