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)

4
votes
1answer
30 views

Unit testing a CharGrid

I wrote NUnit tests for class CharGrid from this homework assignment. My goal here is DRY: I want to keep the testing code as short and simple as possible. In addition, want to run every test ...
3
votes
1answer
30 views

Arrow test Ruby gem

I wrote my first Ruby gem, which is for testing code in the shortest way possible. Here's a usage example: require 'arrow_test' 1 + 1 # -> 3 arrow_test The ...
2
votes
1answer
38 views

Find pairs in an integer array whose sum == 10

I'm practicing for technical interviews and I'm looking for ways to improve my answers/code. Please point out the flaws you see and how I can make this better. Task: Find pairs in an integer array ...
2
votes
1answer
47 views

Testing that a class with a lot of data is inserted into a repository

I have a legacy system with a class with a lot of data. I am creating a web service that inserts a new claimant into that system for a contractor. I can not refactor the claimant object. I need help ...
3
votes
4answers
78 views

Are the words isomorph?

Are the words isomorphs? (Code-Golf) This is my non-golfed, readable and linear (quasi-linear?) in complexity take of the above problem. For completeness I include the description: Two words are ...
0
votes
0answers
41 views

Address validation unit test

This is an example of a unit test I've just written for an ASP.NET controller action to test whether the model's RequiresClassification flag is set to true. The ...
7
votes
6answers
147 views

Super Market Checkout Pricing Strategies

I saw this question and thought it looked like a great opportunity to try my hand at the Strategy Pattern. I've never used it before, but I think I did pretty well. Did I? The code below can also be ...
3
votes
0answers
21 views

Basic declarative style to rotate and crop an image array

I wrote a couple of basic Clojure functions (practicing a declarative style) and I was looking to get some feedback on them. You can see all the code here. Is there anything I could improve on to ...
2
votes
1answer
64 views

TDD: String Calculator Kata

String Calculator Create a simple String calculator with a method int Add(string numbers). The method can take 0, 1 or 2 numbers, and will return ...
4
votes
2answers
70 views

TDD - String Calculator Kata

Would really appreciate it if someone could please review my String Calculator TDD KATA. String Calculator Create a simple String calculator with a ...
0
votes
0answers
20 views

Angular filter to format temperature

Below is a basic filter I created with Angular that does temperature conversion. I'd like to get thoughts on how to improve this code from both an Angular perspective and a general JS perspective. ...
3
votes
3answers
144 views

TDD Supermarket Pricing Kata

I have done the supermarket pricing kata in TDD style and I would appreciate it if someone could review it for me. Kata: "...checkout that calculates the total price of a number of items. In ...
1
vote
1answer
62 views

Creating various types of menus using dependency injection

I am here to discuss what are the possible improvement can be made in order to make the following code covering all the principles of programming paradigm ( SOLID , DRY ...etc ). Basically, I am ...
18
votes
3answers
2k views

“The python that ate a calculator”

In a YouTube video I watched, the speaker said it is important to know how to calculate between numbers of different bases; i.e. two, ten, and sixteen. I was then inspired to write a small C program ...
3
votes
0answers
29 views

Javascript static and prototype mocking

I'm writing unit-tests for my Node.js/Express application with REST endpoints which retrieve stuff via Mongoose from db. Since I'm testing only route functions I want to mock Mongoose by providing ...
0
votes
1answer
29 views

Testing console.log output using assert.deepEqual in NodeJS

I'm new to testing and NodeJS and I'd like to test the output in console.log using assert.deepEqual to test whether or not the result has correct data. For ...
3
votes
2answers
140 views

JUnit testing for Calculator in Java

I made a simple calculator. I would also like to write some simple unit tests for my CalculatorEngine class. I had to make some of my ...
2
votes
3answers
304 views

String Calculator Kata Code in TDD style

I have done the following kata in TDD style and would appreciate it if someone could review my code and my tests. String Calculator Create a simple ...
0
votes
0answers
50 views

Unit testing Socket communication with a race condition

I've developed a library that wraps TcpClient TcplListener objects into the concept of ...
7
votes
2answers
102 views

Traversing binary trees through and through

Given a binary tree, it's quite common to perform some operation on all nodes while traversing pre-order, in-order, post-order or level-order, depending on the task at hand. For example you might want ...
1
vote
1answer
35 views

Testing class that transforms JSON into a spreadsheet

I am creating unit tests but the class uses objects that have long JSON. What can I do to improve the readability of this? In tests, only insert those JSON really needed for the test. The class I ...
1
vote
2answers
46 views

Unit Testing of parser method using py.test

This is my first time using py.test. All feedback for this test case is much appreciated. ...
6
votes
2answers
89 views

Renaming PDF files based on given rules in a text file

I'm learing Python by writing a program to solve some housekeeping I do weekly, namely renaming PDF files according to rules given in a text file. My end goal is to have idiomatic Python, with full ...
5
votes
1answer
57 views

Implementation of the change making algorithm

I wrote a set of python classes for solving the change making problem, in various forms. Given the coin denominations and values: Find all possible ways of making change. Find a best way ...
5
votes
1answer
56 views

Safe cracker string with all combinations

Imagine a safe with a 4-digit code, and accepting a continuous stream of code entries, such that when the 4 digits are seen in the right sequence, the safe opens. Generate a short string that ...
2
votes
0answers
42 views

Find minimum number of coins (count and list of coins too)

For a given set of denominations, you are asked to find the minimum number of coins with which a given amount of money can be paid. Assume that you can use as many coins of a particular ...
5
votes
2answers
252 views

Longest substring with unique characters

Find the length of the longest substring without repeating characters Any comments on my code? ...
3
votes
2answers
64 views

Resource caching in Java with soft references

I'd like to cache some heavy resources locally. The goal of this implementation is to have be able to load resources for an unknown amount of time and then keep them in memory and finally evict them ...
2
votes
1answer
17 views

Simplified doctest

The doctest module seemed easy to implement so I decided to write a simpler version of it. my_doctest.py ...
7
votes
2answers
250 views

A (late) Simple Calculator

As I was looking through my past questions, I noticed my really old calculator question (here and here). Considering it looked like a huge mess, I decided to rewrite it. Coincidentally, the April 2015 ...
7
votes
3answers
147 views

Understanding my permalink service tests

I started writing unit tests cases recently. For now, I created only "perfect case" where there is no error. However, the test seems to me difficult to maintain and difficult to understand. How can I ...
10
votes
1answer
217 views

Rendering an HTML form based on a specification in a string

Here's a brief explanation of my method: Provide a string and parse it to HTML code respecting a specific format. The accepted format is: For dropdown menu : Test DropDown~Select:Options1; ...
3
votes
1answer
71 views

Integer ID pool

I would really appreciate some feedback on the code I wrote to solve the following problem: Design an IdManager. IdManager manages a pool of integer ids. (from 1 to n). It should provide ...
11
votes
4answers
216 views

TDD svino Problem #4 - largest value from concatenated integers?

From this blog post: Write a function that given a list of non negative integers, arranges them such that they form the largest possible number. For example, given [50, 2, 1, 9], the largest ...
6
votes
1answer
85 views

Java 8 unit test for third-party data feeds

Use Case I have a service that does processing of records from multiple third-party feeds. The steps are generally identical for each feed, but each feed is populated in a different location on an ...
5
votes
3answers
151 views

Random letter test

My first test (randomUpperCaseLetter) checks if the returned random letter is an uppercase ASCII one. The second one (...
1
vote
2answers
151 views

Accessing argparse arguments from the class

I have the following sample code running unit tests: ...
3
votes
0answers
67 views

Is this test sane? I may have re-invented the wheel on how to test that a method does not block

I have an Android service which must offload a task to a different thread but schedule the response callback unto the calling thread. After much thinking I came up with this code: ...
7
votes
3answers
129 views

Simple greeting program based with timezone offset

I made a simple set of functions that returns a greeting based on the current time, the user's timezone offset, and the user's level. For context I wrote this as a part of a larger chat bot ...
6
votes
4answers
134 views

Unit testing IValueConverter

I am just starting to implement unit testing into my project and familiarizing myself with NUnit. I have added unit tests for encryption/decryption methods that I have implemented, and am looking for ...
1
vote
1answer
26 views

Splitting a string basing myself on categories

I was thinking about splitting a string based on certain categories, for example alphabetic and numerical, lower and upper case, and even the 3 lines of the keyboard. I wrote a generic function for ...
3
votes
2answers
72 views

Using Mockito to verify that an object is saved

We've been reviewing some legacy code and have found differences in the preferred approach to how to write tests using Mockito. Both the following tests pass but which one is better and why? ...
-2
votes
1answer
63 views

Locker puzzle in Python

(Game: locker puzzle) A school has 100 lockers and 100 students. All lockers are closed on the first day of school. As the students enter, the first student, denoted S1, opens every locker. ...
3
votes
1answer
67 views

Rspec - testing basic functionality - redundant testing?

Being pretty new to testing, I was wondering how many of these tests make sense. restaurants_controller_spec.rb ...
2
votes
1answer
232 views

How to test “verification flow” code? would you test this at all?

I want to write unit-test to my code. However, while writing it, it seems all I can verify is that one method or the other were called once. My class is a manager that execute verification flow. It ...
5
votes
2answers
148 views

Unit Tests for getting the first Monday of the month

I have an application that runs hourly, and I want to use it to also send an email at the start of the day of the first Monday of the month. I searched and found information to help me code what I ...
0
votes
0answers
99 views

Unit testing - Parsing data from the Weather Underground API

I'm writing unit tests for the first time. The tests are for my library on Github. I downloaded the JSON and stored it into a local file that looks like this: ...
10
votes
3answers
485 views

Data Access Layer code for MSSQL Databases

We use this class quite a bit for boilerplate / glue that allows web services and applications to call databases. This code is very important, and I'd like to ensure I'm getting the best performance ...
3
votes
1answer
129 views

Unit testing HTTP requests

I would like to unit test my web requests, so on top of my head I came up with the solution below. Since it seems to be working fine, I'm posting it on this site. Though it doesn't feel very dynamic, ...
1
vote
2answers
44 views

Counting length-2 substrings that are common to two strings at the same offset — Python

I solved the CodingBat task: Given 2 strings, a and b, return the number of the positions where they contain the same length 2 substring. So "xxcaazz" and "xxbaaz" yields 3, since the "xx", ...