Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
1answer
94 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
1answer
85 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 ...
2
votes
1answer
322 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? ...
0
votes
1answer
245 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: ...
-1
votes
1answer
250 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 ...
4
votes
1answer
817 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
2answers
394 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
2answers
10k 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. ...
19
votes
1answer
351 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 ...
12
votes
1answer
1k 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
1answer
2k 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
1answer
71 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
2answers
492 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:...
5
votes
1answer
181 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
1answer
569 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 ...
6
votes
1answer
425 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 ...
10
votes
5answers
3k views

Testing code with Debug.Assert

I have a small little function in a VB6 codebase: ...
5
votes
2answers
131 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
2answers
580 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 ...
7
votes
1answer
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 ...