All Questions
Tagged with unit-testing c++
50 questions
2
votes
2
answers
127
views
C++20 Performance Test Code Generator
My previous question about a generic dictionary class for C++ raised some valid concerns. I have made some modifications based on the previous review, but it needs extensive testing and further ...
3
votes
1
answer
138
views
Testing framework with a single assertion macro
I usually use the Catch2 testing framework in my C++ projects. Unlike other frameworks, it has only one core assertion macro for all comparisons. Instead of writing ...
1
vote
1
answer
104
views
Project for reading and printing IPs
It's a small project which consists of Ip class and functions for reading and printing IPs, unit tests for this code, and a driver app. The driver app is just ...
1
vote
2
answers
1k
views
Multi-Client Socket Communication with Thread Pool in C++
I've been working on implementing a multi-client socket communication system with a thread pool in C++. The system comprises three main components: logger.h, socket.h, and thread.h, which handle ...
1
vote
1
answer
218
views
HTTP routing with Mongoose
I'm trying to extend the Mongoose RESTful server example with URL routing.
This code relies on the Mongoose library available here.
This is heavily inspired by the routes class from this question but ...
6
votes
3
answers
471
views
Unit testing a Linked List implementation in C++
Recently I wanted to use the gtest library to unit test my program but for some reason, it's incredibly hard to make it work and configure (at least for me it was), ...
4
votes
1
answer
284
views
Blocking Queue Class Unit Test
I would like any feedback on making the unit test for a BlockingQueue class more robust or better? improvements to the coding style, use of the ...
1
vote
1
answer
80
views
N dimensional array index utility Improved
This is a continuation from a previous question; I updated the code with the suggestions and added an additional iteration.
Templates are not an option because of the usage: The objects are stored as ...
4
votes
2
answers
680
views
Unit testing for a multi-dimensional array class
I have designed a class bunji::Tensor which is a multi-dimensional array. I have designed it to have a similar interface to a multi-dimensional ...
1
vote
1
answer
320
views
Unit tests for a 2D Vector class
I'm writing a vector class for 2D geometry applications, and below is a rough draft for a unit test using Cpputest. I'm familiar with unit tests, but this is the first I've done for a purely ...
2
votes
1
answer
205
views
Operator overloading in Image class implementation in C++
This is a follow-up question for Dictionary based non-local mean implementation in C++. There are some issues about operators (operator+ and ...
0
votes
2
answers
186
views
Binary search with self-test
Here is an implementation of binary search. Please give feedback on any part but a few specific areas I was wondering about.
Is size_t used appropriately or should ...
1
vote
1
answer
324
views
Unit Tests for the operators of image template class with Boost.Test framework in C++
This is a follow-up question for Tests for the operators of image template class in C++. As G. Sliepen's answer mentioned, I am attempting to use Boost.Test and several test cases are created with <...
1
vote
1
answer
86
views
How to make the initialization of the mocks more readable?
In an Arduino project, I'm using some code which is a slightly modified version of a public library. I made several modifications to it:
I performed some minor changes I needed to make the code work.
...
9
votes
5
answers
2k
views
Unit test for a maximum-finding function
A while ago, I got this question as a part of an interview test which asked to write a function to find the biggest number in a vector and write all the unit tests required to show that the code works ...
2
votes
0
answers
50
views
Unit Test template function with terminal input
I wrote some template function, which helps me with reading input from terminal, doing error handling, validating input.
The full code with template specialisation for strings looks like this:
...
6
votes
1
answer
188
views
A Various Container Type Arbitrary Nested Iterable Generator Function Implementation in C++
This is a follow-up question for std::array and std::vector Type Arbitrary Nested Iterable Generator Functions Implementation in C++ and std::deque and std::list Type Arbitrary Nested Iterable ...
6
votes
1
answer
157
views
Non-nested std::deque and std::list Generator Function for arithmetic_mean Function Testing in C++
This is a follow-up question for A non-nested test_vectors_generator Function for arithmetic_mean Function Testing in C++ and An arithmetic_mean Function For Various Type Arbitrary Nested Iterable ...
7
votes
1
answer
497
views
Generic test case templates
I often find that when I am writing, refactoring, or reviewing code that I want to do some simple testing. There are many existing test frameworks such as gtest and cppunit but my desire was to ...
5
votes
2
answers
397
views
Ray implementation
Problem Statement/Context:
Represent a ray, given a origin and direction. Besides this a min_t and max_t value are defined. ...
1
vote
3
answers
266
views
high card game implementation
I wanted to write a simple implementation for a high card game. Basically two cards are drawn and the higher one wins. Additional rules: support for multiple decks, if same suits drawn then the ...
5
votes
0
answers
167
views
Using an extra mock simply to take advantage of the behaviour observation tooling
I'm writing integration for a project, but our framework doesn't provide any ability to inject dependencies, so I've written tests with a unit testing framework (GTest) and used a mock (GMock) in an ...
3
votes
4
answers
149
views
PropertySet implementation
Problem Statement:
Store properties with a certain name (key), type and value. The key is always a character literal and the value can be of type bool, ...
5
votes
2
answers
1k
views
classes to represent a HTTP request and response in C++
I am writing an HTTP message coder/decoder. In my decoder I parse http messages into a http_request or http_response. In my encoder I encode one of these classes.
Representing the messages is the ...
3
votes
0
answers
40
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 ...
6
votes
2
answers
117
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 ...
3
votes
1
answer
130
views
Simple stringifying using << operator
Background
I wrote my_length class and some code. my_length can be stringified using ...
1
vote
1
answer
264
views
Prepare a cross-platform QT C-wrapper class for unit testing and mocking
The situation
I recently started a cross platform QT project (arm, linux-x86, windows) that
aims to interact with CAN-Bus hardware. I want to learn and get used to unit testing from scratch as good ...
7
votes
3
answers
2k
views
Program to see how many points lie strictly inside a convex polygon
The program takes in a set of coordinates that defines the polygon. It then takes in a set of points. The idea is to find out how many of these points lie strictly inside the convex polygon (not on ...
1
vote
1
answer
3k
views
Testing the performance of a loop for a vector of unique_ptr
I wrote this simple program that tests how long it takes for a loop to iterate through a vector<unique_ptr<>>. I'm wondering if this a good way to ...
0
votes
1
answer
1k
views
Writing unit tests for constructor with shared_ptr arguments
Should I write unit tests which verify that constructor is throwing in simple cases when a nullptr was provided instead of a ...
2
votes
1
answer
261
views
Singly linked list data structure design, implementation and unit testing
Design a singly linked list data structure that supports following operations: size, is_empty, ...
4
votes
2
answers
348
views
linspace c++ and unit tests in catch BDD
I have implemented matlab's linspace function
...
6
votes
1
answer
267
views
Code to check for memory leaks
I want to write a header file for c++. When included in a program, the header file overloads the new and delete operators so ...
2
votes
1
answer
234
views
Compression unit test data "easy case"
In another post I created a piece of data, which make compressor annoyed.
Create 'worst case test' data for compression test
Now I am trying to make it happy. I generate another data set, ...
8
votes
2
answers
284
views
Create 'worst case test' data for compression test
I am going to prepare some test data for a compression test. One of the them is the 'worst case test', which should make the compressor work worst. Use random number to generate such a file is an ...
3
votes
1
answer
107
views
Small unit testing framework
Here is a single-header small unit testing framework I wrote, that makes use of mostly preprocessor macros. I made it for knowing how unit testing works and, also, try to depend less of third-party ...
5
votes
2
answers
5k
views
C++ Query String Parser
This query string parser is intended to parse the parameters and values of a parser query string. I'm particularly concerned about my use of std::move(...).
I ...
13
votes
2
answers
6k
views
Unit-testing friendly singleton
In my project we have a few singletons, which tends to be problematic in unit tests. So I wanted to find solution for the problem. Here is what I came with so far:
smart_singleton.h
...
2
votes
2
answers
183
views
C++ Minimalistic Unit Testing Library
I was looking for a unit testing library for C++, and I found many. Unfortunately, I decided I didn't want to use any of them. I decided to make my own.
This is the result. I made heavy use of the ...
6
votes
1
answer
167
views
An attempt on unit testing in C++
I have no much experience with C++, so it is about time to start actually doing something about it. All in all, I coded this tiny unit test library:
assert.h:
...
11
votes
1
answer
153
views
Find all the primes less or equal than N
This is not a novel interview problem. But I want to address it with the following points:
Implement the algorithm with Object-Oriented Design principles in mind.
Optimize the solution, if there are ...
12
votes
3
answers
7k
views
Unit testing with a singly linked list
To hone my skills with C++11, I'm implementing a singly-linked list based on the requirements I found at this link.
I've implemented code that supports the following subset of requirements from the ...
5
votes
2
answers
1k
views
String Token Generator for ExpressGenGen
StringTokenGenerator is an interface (or abstract class) I've created to the specific task of generating a string token of a given character set. It allows ...
2
votes
1
answer
39
views
Implement test which tries function with diferent params and expected results
What could I improve in the following code? The goal is to test a function againts a table of input parameters and compare to some expected results with some tolerance (as there are random variables ...
12
votes
1
answer
2k
views
Minimal C++ Unit Test Framework
I've written a minimal unit test framework. The goal was to allow assertions of booleans, for equality and catched exceptions. Two things are bugging the most. That assertions have to rely on macros ...
4
votes
1
answer
2k
views
Test with array and mock
Here is my function I want to test:
...
5
votes
3
answers
3k
views
Implement strtod parsing
In this comment the OP wrote,
I am a newbie so i would like to know how would i parse the negetive numbers/arguments ?
In this answer @200_success showed an implementation using the strtod ...
7
votes
1
answer
361
views
CppUnit test suite for testing a routine
I wrote a CppUnit test suite to unit-test the code that I posted here which is a single routine that proposes how a Lua expression could be auto-completed.
What do you think? I appreciate all the ...
2
votes
2
answers
225
views
should DRY apply to unit tests as much as production code
I have a unit test method that looks like this:
...