Skip to main content

Questions tagged [assertions]

In computer programming, an assertion is a predicate (a true|false statement) placed in a program to indicate that the developer thinks that the predicate is always true at that place. If an assertion evaluates to false at run-time, an assertion failure results, which typically causes execution to abort.

Filter by
Sorted by
Tagged with
3 votes
1 answer
124 views

A simple unit test library for C - version II

I have improved my code here and it looks like this: Code assertlib.h: ...
7 votes
1 answer
830 views

A simple unit test library for C

(This post is followed up by this one.) I have rolled this simple unit test library for C: com_github_coderodde_my_assert.h: ...
3 votes
1 answer
504 views

My own ThrowHelper extension methods

I really like ArgumentNullException.ThrowIf(...) and ArgumentException.ThrowIfNullOrEmpty(...) and there are upcoming ones in ....
4 votes
1 answer
688 views

Python function: user input to get positive integer using assert

Is it a bad thing to use asserts to validate user inputs? Or should I keep using an if statement in case the number isnt positive? Code with assert statement: ...
0 votes
1 answer
178 views

Parameter Scaling C++ Driver program

The question is: In many mathematical problems, the parameters need to be scaled, either to convert between units or to standardise measurements to a certain range of values. Write a void function ...
0 votes
1 answer
896 views

User Input in class sanitized

I want to sanitize my user input in my class. All is working as expected but first of all, I would like to avoid to set a default value for my digit parameter. ...
0 votes
1 answer
95 views

Type that returns a result based on some logic [closed]

I have a type that returns a result based on some logic. The result contains a message. Should a good unit test check that the message is correct? A negligible amount has changed as I'm not allowed ...
0 votes
1 answer
492 views

MS Fakes Shims. Assert "was called" (by closures)

Is it a good or bad practice to use closures for asserting the method was called in such a way? The method set a shim and return an Action wich both capture local mutable variable: ...
2 votes
1 answer
909 views

Custom timer assert

I would like to make a custom Assertion for my unit test, which would measure the execution time of two c# functions and compare them. I have written the code below, but there is a better way? ...
19 votes
1 answer
520 views

Suggesting "safe enum" class for ISO C

There are quite some questions and answers about how to make enum really type-safe and I didn't find a solution that ensures both type safety and valid values. So I ...
0 votes
1 answer
351 views

Test helper method to assert if text could be found

Lately I've been getting a lot of critique in my code reviews at work, where typical comments have been that my variable names are unclear/confusing, flow in method could be simplified, unnecessary ...
3 votes
1 answer
1k views

Verifying user accounts on SMTP servers

I've been writing a basic script to enumerate SMTP users (via a user dictionary) on poorly configured SMTP servers. In scripts like this, I usually see arguments handled as follows: ...
3 votes
2 answers
1k views

Simple JavaScript precondition checking implementation

I am writing a JavaScript application and would like to validate function arguments in many places. Most of these checks will be for correct argument types, or numeric values within specific ranges. ...
5 votes
2 answers
16k views

Unit testing private constructors and getter setters

I have a class Address, a class AddressTest and I am trying to write unit tests for its constructors and getter setters. ...
13 votes
1 answer
2k views

Compile-time printf-style format checking

Inspired by this open ticket on Boost, this seeks to complete the work there. Given a printf-style format string and associated arguments, a static_assert is ...
5 votes
1 answer
3k views

Compile-time printf format checking

Compile time checking of printf-like format strings Inspired by this open ticket on boost, this seeks to complete the work there Given a printf-style format string and associated arguments, a ...
1 vote
1 answer
72 views

How can I ensure some structure for classes for a plug-in system written in Python? [closed]

I have written a toolkit (hwrt) which has a plugin system. One type of plugin is a feature (see this) for many of them. There are some restrictions of feature ...
4 votes
2 answers
629 views

NSAssert or NSLog in defaults switch case

I am wondering if I should use NSLog(@"Switch out of range") or NSAssert(FALSE,@"Switch out of range"); in the following example:...
10 votes
5 answers
3k views

Testing code with Debug.Assert

I have a small little function in a VB6 codebase: ...
5 votes
1 answer
227 views

Better way to assert correct return values in Groovy

I have written a function that returns me the duplicates of a list: ...
10 votes
1 answer
958 views

Automatically run doctest every time program is run

I would like this to happen every time I run a program from the command line. Is my approach Pythonic? I'm interested to know whether there is any problem with readability or correctness. Any general ...
8 votes
1 answer
2k views

Vector of derived classes

Everyone knows you can't put a Derived in an std::vector<Base>. I decided to implement a collection which does allow you ...
6 votes
1 answer
512 views

How should I structure my Unit tests for minimal Asserts?

I always see comments about how a Unit Test should only be testing one piece of functionality. For the most part, I definitely agree with that assessment. However, I'm working on testing a method ...
5 votes
2 answers
368 views

What might be another way to test if int is 32 bits wide at compile time?

Below is code that will compile when INT_MAX is equal to 232. It will generate a compiler error when INT_MAX is not equal to 232....
5 votes
2 answers
703 views

Defensive programming type-checking

I have issues with dynamically typed languages, and I tend to worry about type a lot. Numpy has different behaviour depending on if something is a matrix or a plain ndarray, or a list. I didn't ...