Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.
1
vote
1answer
21 views
Idiomatic F# unit test using xunit and unquote
I'm writing some unit tests for testing C# code but I'm using F# and Unquote for the first time for the unit tests and would like some input as to how I might make the tests more 'f-sharpier' to take ...
2
votes
0answers
27 views
Roman number converter in Kotlin
I'm learning kotlin and java. As a code-kata I wrote the roman to decimal converter. I'd be very grateful for code review.
I was trying to keep things simple and funcional. I'd especially appreciate ...
5
votes
1answer
26 views
Testing file IO errors in python
Below is a simple class with two methods: the first calls open() to read in a file. The second calls the first method and does error handling.
There is also a ...
1
vote
2answers
62 views
Webdriver-based test that uses configuration parameters from a database [on hold]
I am writing automated functional tests for my application. To interact with the application, I use the SQL database to retrieve data and validate data.
One of the challenges that I'm facing is that ...
1
vote
2answers
38 views
Function for getting strings consisting of random characters
I've made this function for to be used while testing.
...
5
votes
0answers
40 views
Mocking config data in JavaScript unit tests
I'd really like someone to sanity check my approach for unit testing the summarise() function and mocking its dependencies.
Background
Each option has a set of ...
4
votes
1answer
37 views
Takes function and throws exception if passed function doesn't throw an exception
The code below is part of a toy test assertion library I've written.
I'm looking for feedback specifically on lines 4 - 9. I'd like to extract them from the ...
3
votes
4answers
72 views
Unit testing for concatenating two int arrays
Using Java 1.8, I created the following implementation to concat two int arrays:
...
2
votes
1answer
75 views
Dynamic wrappper used to unit test ASP.NET Core MVC Controllers that return anonymous objects
Originally created for this answer on SO, I thought there was still room for improvement on the initial basic idea.
Also thought about using an extension method to make using syntax simpler.
Here is ...
8
votes
1answer
108 views
Multiplication or addition of decimals or integers for prehighschool; non deterministic testing
I'm creating a simple android app for pre-highschool students which teaches the very basics of addition or multiplication of integers or decimals.
The part of the program in this question is aimed ...
10
votes
2answers
226 views
Converting Morse Code
Challenge
Write a program which reads a file containing Morse Code and outputs the conversion.
Specifications
The first argument is a path to a file.
The file contains multiple lines.
Each line ...
2
votes
1answer
60 views
Unit test code for a private median-of-three function, using reflection [closed]
A Junit test class is used to test the class LibraryCounter. Reflection was used to test the private methods. This made the code much more complicated.
...
1
vote
0answers
33 views
Jasmine Unit tests for simple Angular backend interaction
I have a simple Angular application that lists some object requests from a backend, allows the users to click once to edit the item, and then click again to update the object in the backend.
Here's a ...
1
vote
0answers
37 views
Event log implementation with TDD
Below is some code that implements an 'event log' whose purpose is to record events and periodically check that all events were recorded in chronological order. The collection of events must be ...
3
votes
1answer
84 views
Simple Wizard Goblin User Story Test Driven Development
I have written this to practice Test Driven Development. I would like to know if the process is right and how it could be improved.
Problem Statement : A wizard can cast spell on goblin and make his ...
7
votes
1answer
36 views
Python App that parses file for lines that match a format
I recently wrote some code that was dinged on not having well defined tests and poor modularity. Was hoping someone could review my code and give me pointers on how to create more well-defined tests (...
6
votes
1answer
132 views
`Piece` class as part of implementation for the Tetris game
Here is my Piece class as part of implementation for the Tetris game. Critics of any kind and levels are very welcomed. If possible, I want my code to face the ...
0
votes
0answers
45 views
Laravel Unit Test for API
I'm currently building an API with Laravel 5 and I've written some unit (or integrated?) tests for it. I've been reading a little about unit test and how to not overdo it and I would like some input ...
4
votes
1answer
153 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
271 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
222 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
33 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
45 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
34 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
48 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
45 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 ...
3
votes
1answer
48 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
40 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.
...
10
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
87 views
4
votes
2answers
138 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
81 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 ...
0
votes
1answer
107 views
Iterative algorithm to convert a signal to Fourier series
I want to show you an iterative algorithm to convert a signal to a Fourier series. When I ran unit tests I gaven following results:
one iteration: 1 sec, passed;
ten iterations: 3 sec, passed.
I ...
4
votes
3answers
83 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
88 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
55 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
52 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
130 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 ...
5
votes
1answer
63 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
50 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
105 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
48 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
61 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
51 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
97 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
100 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
54 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
88 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 ...