Questions tagged [unit-testing]

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

Filter by
Sorted by
Tagged with
2
votes
1answer
54 views

A simple priority queue in Java via linked list sorted by priority keys

Now I have this very simple priority queue. add and changePriority both run in \$\mathcal{O}(n)\$ and ...
1
vote
2answers
72 views

Unit tests for anagram finder

I did this test for a job and the feedback was: "while many were added to test private methods, they did not do anything to ensure the public interface worked correctly, edge cases were missed" But ...
2
votes
1answer
54 views

Rustacious way of checking if string ends with any suffix from a selection

What's the best way to check if a String ends with any of multiple suffixes in Rust? I have a working, naive solution: ...
1
vote
0answers
36 views

Tests for redis wrapper

I've written a wrapper package for redis. The idea is to be able to provide better error reporting with the package, as well as integrating stats and logging at a later stage. For now it's just better ...
3
votes
3answers
94 views

BindableBase with a throttle

I have project where I'm using BindableBase for my INotifyPropertyChanged implementation. Some of my objects however are ...
5
votes
1answer
31 views

CandidateArchive for model-assisted multi-fidelity global search algorithm

For my research I'm working on global search methods where a candidate solution can have it's fitness (=score) evaluated in multiple fidelities (=accuracy levels). The goal of the ...
4
votes
1answer
47 views

PyTorch Unit-testing in Python

I'm new to PyTorch and I'm writing a unit test for an activation function I'm making. I plan to test against a reference implementation for this function. I want to approach this in a test-driven way,...
2
votes
0answers
64 views

Sending push notifications to a user

I have a function whose responsibility is to send a push notification to a user. I call this function from a view in flask framework. I have read multiple articles around refactoring and good designs ...
1
vote
1answer
47 views

Idiomatic way to write proper F# (x)unit + fsunit tests?

I am writing some unit tests using XUnit in F# and I am wondering what is the most idiomatic way in the F# sense to write them. Let's start a simple case: ...
10
votes
4answers
2k views

AsyncDictionary - Can you break thread safety?

This class is an Async/Await wrapped Dictionary. Of course it doesn't technically implement IDictionary, but the functionality is basically the same as an IDictionary. It achieves similar ...
5
votes
1answer
54 views

Implementing d-ary heap

I'm trying to Implement a d-ary heap. A d-ary heap is just like a regular heap but instead of two childrens to each element, there are d childrens! d is given when building a heap, either by giving an ...
1
vote
0answers
77 views

Building maps for Dgraph integration tests in Java 8

I want to refactor this in Java to reduce my code duplication. ...
3
votes
1answer
85 views

Ensure difference between sets

An endpoint that my application interacts with allows you to specify which fields are returned in the JSON result. My application will then map the JSON to a POJO using Jackson. Quite often I add more ...
2
votes
0answers
39 views

Laravel testing for compatibility between old and new password-hashing schemes

I currently have an event listener tied to Laravel's Attempting class. The listener is designed to rehash an old password to something newer. The current DB stores ...
16
votes
3answers
2k views

ExactlyOne extension method

I often find in codebases something on the order of if (sprockets.Count() > 0) which is easily replaced with LINQ's ...
9
votes
2answers
755 views

Recursive search on Node Tree with Linq and Queue

This code is now maintained on GitHub I've created a Node class which contains two important properties: ...
12
votes
2answers
1k views

Calculating Fibonacci sequence in several different ways

I'm doing an experiment trying to freshen up my unit-testing and learn dynamic programming. Every test passes but I'm curious of the result of some of them and worried if I'm doing the testing ...
3
votes
3answers
107 views

Unit tests for a function that calculates demerit points for speeding

I'm currently working on a unit testing course (NUnit 3.x). I've been tasked with a simple class to test all edge cases. ...
1
vote
1answer
79 views

Bowling Kata in Java

I am sharing my Bowling Game Score Kata made in Java, it is available for whoever wants to code review it. I appreciate any comments. ...
0
votes
1answer
99 views

Abstracting an Email Notification Service & testing the the logic of the used abstract factory

In my application I have an Interface IEmailNotification that represents an Email and the concrete implementations have nothing to do with ...
1
vote
0answers
28 views

Clojure test for Git operations

Is this code a good test for a testable Clojure code? ...
2
votes
1answer
60 views

Table class to fill array structure with values

The code creates a table and adds rows and columns. Does it make sense to write the code like this? Would you design it differently? Is there a better OOP approach to this? ...
1
vote
1answer
43 views

Test Driven Development Roman Numerals php

I just learned about Test Driven Development on a podcast yesterday. So I decided to try it out today by writing a roman numerals to integer converter (per their suggestion). I've never written Unit ...
3
votes
2answers
83 views

Simple OOP currency converter - follow-up

This is a follow up question on this post This is what I changed on my previous code: I use Exchanger and PairCurrency class ...
1
vote
1answer
48 views

Creating a real unit test in Karma for Angular code [closed]

This is a piece of test code made for the Angular application. The router object is a mock provided by the RouterTestingModule dependency. I wonder if such a test can be considered a unit test (...
8
votes
2answers
465 views

Simple Unit Test in C

Simple UnitTest macros utility in C. I decided to make this to be able to more easily organize my tests and I emphasized on readability. Please tell me what you think and if this utility would perform ...
3
votes
0answers
93 views

JavaScript `localStorage` with `document.cookie` fallback for static web sites

The Code I've got things operating as desired so far and am hoping fresh eyes can point out any mistakes or bits that can be improved, a live demo is hosted and updated on GitHub Pages, Travis-CI ...
2
votes
1answer
53 views

Non-testable class wrapping Java Properties with basic logic

I have written a simple java.util.Properties wrapping class. Unfortunately, in my opinion, it isn't testable at the moment and I don't have any idea how to improve ...
0
votes
2answers
59 views

Wrapper class for system dialog to allow for dependency injection

The following class is a wrapper for Microsoft.Win32.SaveFileDialog. I've implemented the usage of Microsoft.Win32.SaveFileDialog...
1
vote
2answers
52 views

PHP unit test to confirm that a validator is being called correctly

I have a Responder class whose prepare method takes an entity, checks it with a validator, and returns a response or errorResponse based on the results of validator....
10
votes
2answers
268 views

Verhoeff check digit algorithm

A recent question on credit card validation here on Code Review, led me down a dark rabbit hole of check digit algorithms. I took a stop at the Verhoeff algorithm and tried to implement it myself. ...
2
votes
1answer
81 views

Removing first or last character of a string with unit-testing

I am trying to remove a duplicate letter of first or last letter, with an exception of containing 'a' as first letter and 'l' and 'e' as last letter. However, this code does not look efficient to me ...
0
votes
2answers
52 views

Tests for Salesforce controller concerning candidates and notes

I have this controller and some test cases. Any corrections/advice are appreciated to make them better. ...
3
votes
0answers
42 views

Simple REST Base Web Server with Unit Tests

I am building out a simple web server in Go. My goal is to expand on this framework in a different application I am building. Here is my github repo https://github.com/jmacnc/gowebserver Is what I ...
28
votes
4answers
4k views

FIFO data structure in pure C

I programmed a generic queue in pure C and I'd love to receive some feedback from other programmers. You may use the following questions to guide your review. Is the API well thought and idiomatic? ...
0
votes
0answers
59 views

Writing a unit test with Jest and Vue/test-utils, using a spy or calling a function directly?

I have a switch/case function that I'm testing and I have two versions of a unit test. I do not know which is the preferred method of writing a good test. component ...
3
votes
1answer
58 views

Assigning test-data parameters by name

When creating data-driven tests with xUnit we can use the MemberDataAttribute to get the data from a member of this or other ...
5
votes
0answers
202 views

Cubic spline interpolation in Python from scratch

I implemented the cubic spline interpolation explained in https://en.wikipedia.org/wiki/Spline_interpolation as a Python class. Of course, such an interpolation should exist already in some Python ...
7
votes
1answer
54 views

Binary Heap implementation in Common Lisp and tests

I implemented a basic binary heap in Common Lisp to learn programming using the CLOS. It is quite neat and self-contained, the core of the program is about 100 SLOC. The whole repository can be found ...
1
vote
0answers
31 views

GUI Button Element with Unit Tests follow-up

This is my second attempt with unit-tests. Like my previous attempt, I would prefer a focus on the unit-tests, however I am always happy to improve my code in any way reviewers can help. Once again ...
2
votes
1answer
66 views

Minimal Haskell Unit Testing Framework

I'm trying to come up with a unit testing framework for Haskell that is small and self-contained produces TAP-compatible output exits abnormally on failure (instead of relying on the TAP consumer to ...
6
votes
2answers
66 views

GUI Button Element with Unit Tests

I would like a review on just a single class today. More important to me than a review on the class itself, however, is a review of the unit-tests I wrote for it. You see this is my first attempt at ...
4
votes
1answer
85 views

Unit testing extension method adding view location expander

Introduction I'm writing unit tests for an extension method I wrote. Its only purpose it is to wrap startup logic which extends ViewLocationExpanders list by an ...
1
vote
1answer
47 views

Unit Test case to check if localstorage is empty once I logout of the Web app

I am trying to clear my localstorage when I am logging out of the application. I want to write a unit test case in Jasmine to check if this task is performed when logout function is run. I am writing ...
1
vote
1answer
60 views

Abstracting getter and setter method references for testing

Is the following code easy to understand? If not how should it be changed to be more understandable. The purpose of this is reducing similar code in unit tests. This avoids repeating lines for calling ...
1
vote
0answers
59 views

Linked list implementation along with unit test - Round 3

Here are the changes I've made thanks to suggestions made by @vnp, and @Henrik Hansen. Here is the link to the previous code review: Linked list implementation along with unit test - Round 2 I've ...
3
votes
2answers
65 views

Linked list implementation along with unit test - Round 2

Here is the link to the next round of code review: Linked list implementation along with unit test [Round 3] Here's the link to the previous code review: Linked list implementation along with unit ...
7
votes
1answer
204 views

Linked list implementation along with unit test

I've already made all the changes suggested here. Here is the link for round 2: Linked list implementation along with unit test [Round 2] I want to see how other people think of my code, so here it ...
7
votes
1answer
117 views

TDD tests for every view and its permissions in a REST API

I am currently developing a Django Rest Framework API with TDD. I have 15 tests and counting for two views, which doesn't seem right to me. It takes me a lot of time to write the tests and a lot of ...
4
votes
4answers
270 views

Poker Game: Unit testing different poker hands without violating DRY principles

I'm currently in the process of refactoring an old poker game which violates many of the SOLID principles. I was trying to use the TDD approach to refactoring and I found myself having to hard code ...