Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.

learn more… | top users | synonyms (1)

1
vote
0answers
9 views

SVG photo mosaic creator

I got this as part of some interview assignment. After some head scratching I think I have done quite well as the result can be seen here: After transformation(10x10 tile): More crisp picture ...
5
votes
3answers
215 views

Finding the duplicate with an array with 1,000,000 integers between 1 and 1,000,000

I recently had an interview and got to phase 2 which is a coding assessment. One of the questions was: Given an array with 1,000,000 integers between 1 and 1,000,000, one integer is in the array ...
12
votes
6answers
2k views

Find the first non-repeating character in a string: (“DEFD” → E)

I recently had an interview and got to phase 2 which is a coding assessment. One of the questions was: Find the first non-repeating character in a string: ("DEFD" --> E) I didn't pass the coding ...
1
vote
1answer
221 views

Validating that only certain values are unset

I am checking data output in some testing code, and only some fields can be None, but I think this can be better: ...
3
votes
1answer
30 views

Unit tests for custom Map wrapper

A while ago I asked for a code review of my automatically keyed map and I have recently had the time to get around to writing some unit tests for it using JUnit4. The test ensures that all of the "...
2
votes
2answers
37 views

Random distribution in Ruby

Below is a Ruby implementation of a random statistical event, based on a hash with the actual observed counts of outcomes. I'd be interested in feedback in particular on what techniques I might use ...
2
votes
1answer
30 views

A utility class for fractions

I've been working though Project Euler problems using JavaScript, and along the way I've found it useful to create "classes" for different types of numbers (like an integer that can be arbitrarily ...
1
vote
1answer
42 views

Hamming distance in Scala

Problem Write a program that can calculate the Hamming difference between two DNA strands. GAGCCTACTAACGGGAT CATCGTAATGACGGCCT ^ ^ ^ ^ ^ ^^ Code ...
3
votes
0answers
39 views

SQLite Databse inserting + Unit tests in Java

Genereal Introduction This is my first project which involves a Database which involves testing (especially unit testing) where the quality is really important for me. The long term aim is to ...
2
votes
1answer
46 views

class Taboo<T> — sort passed in List<T> according to 'rules'

I know as a matter of fact that there are many areas upon which my code could be improved. I was wondering if anyone can provide me with suggestions on how Taboo ...
0
votes
0answers
29 views

Identifying Types of Triangle in Scala

Below is my solution to this exercise. Write a program that can tell you if a triangle is equilateral, isosceles, or scalene. The program should raise an error if the triangle cannot exist. ...
9
votes
4answers
2k views

BigInteger formatting for endless tower defense game

I am working on an endless tower defense game in Unity. To keep track of money, damage, hitpoints and stuff like that I will be using BigInteger, which can ...
3
votes
1answer
62 views

Anagram in Scala

Code ...
4
votes
2answers
136 views

Find items that appear the same number of times in two collections

Here is a Java collection puzzle I found online. I was wondering if anyone can provide me with suggestions on how Appearance and tests can be improved. Suggestions ...
2
votes
2answers
74 views

Returning a filtered list of iPhones

I have just received feedback regarding a junior dev test that I submitted. It was unfortunately not great, and the recruiter could not articulate the issues, I tried to show that I was thinking about ...
4
votes
3answers
77 views

Nucleotide count in Scala

This is my second day in learning Scala and I still need to develop a taste of functional programming, I often find myself doing imperative coding. Below is the result of my TDD practice. Code ...
5
votes
1answer
84 views

Validation extensions v2

I have still another version of my validation extensions. I've reworked it and added some new features. It doesn't relay on expression trees any more but as a compensation the same extensions can be ...
3
votes
1answer
52 views

Lombokython - Automatic __eq__, __hash__, __repr__

I recently decided to code some in Python after coding in Java using lombok for quite some time. However, I got bit real hard when I forgot to implement __eq__, ...
5
votes
1answer
49 views

Reddit mirror encryption challenge

While reviewing Encryption using a mirror field, I decided to write my own solution from scratch. The challenge, from Reddit's /r/dailyprogrammer, is to implement a monoalphabetic substitution cipher ...
5
votes
2answers
116 views

Mars Rover Simulator

Problem Statement Consider a rover and a plateau of size nxn. The rover takes three type of instructions L,R and M. 'L' and 'R' rotate the rover in the left and right direction. 'M' moves the ...
4
votes
1answer
54 views

UnitTesting with Mocking and Dependency Injection using Ninject

I have the following scenario that I have not come across so far using Ninject. I have the following class structure (simplified for easy of reading :]). First the abstract base class for all ...
2
votes
1answer
48 views

Interface to the Force.com REST API

I'm implementing an interface to the Force.com REST API, with very specific ideas about which parts of the API I need. My problem is with testability of consumers of this API abstraction. The first ...
2
votes
2answers
103 views

Name-deduplicating class

Recently I asked a question on Programming SE about public vs private methods fo unit testing, which generated a lot of interesting responses. I only posted a skeleton of the code there, as it was a ...
5
votes
1answer
44 views

Calculate attendance compliance based on attendance record

This is part of a larger working system which I'm now trying to clean up. In the interests of making the system more test-able I'm splitting up the functions which can be split, but this 100-line ...
1
vote
1answer
40 views

Unit test with check testing framework

I have some code where the purpose is the decide if a char is between quotes in an expression. For example, awk '{print $1}' has a ...
2
votes
1answer
60 views

Check binary tree symmetry by reversing, checking equality, coverage tested, makefile

A few weeks ago I recall a HackerNews story (found it again: "I Don't Want to Hire You If You Can't Reverse a Binary Tree") about reversing a binary tree (with, as I remember it, the end goal being to ...
4
votes
1answer
49 views

Count words in string and tally up the repetitive words

I'm an elixir beginner. I'm doing the word count exercise of exercism website. The word count exercise returns a map with the word as the key and the number of instances as value. The exercise ...
4
votes
2answers
76 views

Unit testing Equals, hashcode and comparator - asserting contracts

After reading Joshua Blosh's Effective Java 2nd edition, I decided to implement equals, hashcode and comparable(where applicable) to every class I have been implementing. I have written a generic ...
4
votes
1answer
97 views

Algorithms to find various kinds of paths in graphs

I think many here are familiar with the graph data structure. Not very long ago, I implemented as an exercise a supposedly simple Graph application that does some traversals. To note, the most complex ...
2
votes
1answer
52 views

Raindrops in Java

Problem Statement: Write a program that converts a number to a string, the contents of which depends on the number's prime factors. If the number contains 3 as a prime factor, output '...
4
votes
3answers
74 views

Binary string to decimal conversion

Problem Statement: Write a program that will convert a binary number, represented as a string (e.g. '101010'), to its decimal equivalent using first principles Implement binary to decimal ...
5
votes
1answer
71 views

Let's revisit Roman numbers

Problem Statement: Write a function to convert from normal numbers to Roman Numerals: e.g. 1 => I 10 => X 7 => VII Code: ...
3
votes
2answers
86 views

Let's play Scrabble

Problem: Write a program that, given a word, computes the scrabble score for that word. Code: ...
1
vote
1answer
36 views

Private method to validate Excel header

I am new to unit testing and I am unsure how to design classes that use third party libraries, so that I can easily test them. The example I'll use is with EPPlus-...
4
votes
3answers
115 views

Solution for the BankOCR kata

Next Saturday I'd like to conduct a TDD demo in our local developer meetup. For this purpose I want to implement the first user story of the BankOCR kata from the Coding Dojo Wiki. Here is the ...
8
votes
1answer
117 views

TDD - Kata - String Calculator

This is my first TDD Kata I've done and I'd appreciate it if someone could review it. String Calculator Create a simple String calculator with a method int Add(string numbers) ...
3
votes
2answers
77 views

Unit test for a method that adds tweets to a database

I have a class which inserts a list of tweets to a database table and also inserts the tweet's key with the associated filter's key to a many-to-many table. I am testing the sole public method of this ...
1
vote
0answers
30 views

Testing a method which coordinates multiple objects

I have this class with one method, which uses three different objects to perform a task. ...
2
votes
3answers
105 views

Code Smell in Unit Testing Serialized Classes

I can feel that something is wrong with my code. Here's an excerpt where I think the code smell is... ...
4
votes
1answer
60 views

Unit Testing Input Class in Monogame

I'm new to unit testing, and to learn, I've decided to "contribute" to Monogame to help with their testing efforts. The issue at hand is to test the input device classes. I've started with the GamePad ...
2
votes
1answer
101 views

How do you name a something as approximately equal?

Let's say I following have code: ...
2
votes
1answer
75 views

Testing a shell command interpretor

I've written tests that use Bash for testing a custom shell. I think the tests work but I'm sure you know better because this is my first test I write this way. ...
5
votes
1answer
63 views

Alternate letters to UpperCase

As an exercise I repeated this Java question, but in Go: Convert string to mixed case The objective is for every second letter to be converted to uppercase. Go string processing is relatively new to ...
8
votes
3answers
533 views

A reference source for primes up to 64K (for unit tests)

In order to code the tests for my number theory library (a collection of routines that proved handy for coding challenges) I needed a reference source for primes up to 2^16. I did not want to ...
4
votes
3answers
159 views

Count words in a string

Continuing my TDD from exercism. Write a program that given a phrase can count the occurrences of each word in that phrase. For example for the input ...
3
votes
1answer
38 views

Method injection into TestClass local namespace for automatic generation of Python unittest “test_xxx” methods

I am writing a series of unit tests in Python 3.5 unittest, which run the exact same test methods on different datasets. The purpose is to validate proper behavior ...
7
votes
3answers
212 views

Nucleotide Count

I am learning Java and hence practicing it from here. The solution seems pretty trivial to me but still I would like to have a honest review which would guide me to following ideas: Am I maintaining ...
4
votes
0answers
91 views

Unit Testing Against Exceptions

I am writing a Swift library. I'm writing unit tests for that library. I am afraid that some of the code that I am testing will possibly throw exceptions. In Swift, we can handle errors, but we can ...
3
votes
0answers
60 views

MSTest Data Driven Test Inline Data

Background: Didn't what to have to reference bulky 3rd party lib for inline data driven tests and wanted to use standard MS testing framework. Created helper ...
3
votes
1answer
115 views

Making the Levenshtein distance code cleaner

I was writing an implementation of Levenshtein distance in Python and I found my code really ugly. Have you any idea how to make it more elegant? ...