C++ :: Running Unit Test On Library - Checking For NAN?
Jan 31, 2012
I am running a unit test on a library and this line keeps failing on Fedora 16, G++ 4.6.2
Code:
assertNAN(double, std::numeric_limits<double>::signaling_NaN()); //sanity check
The assert looks like this
Code:
//needs to copy it so that if its a function call it only does it once
#define assertNAN(type, one) {
type val = (type)one;
std::string lag(#one);
lag += " not a number";
[Code] ...
I am compiling with -DNDEBUG -O3 -ffast-math -fexpensive-optimizations to simulate a production environment. Is there a way to test for NAN consistently?
View 11 Replies
ADVERTISEMENT
Feb 6, 2014
I have function that returns historical data. I can access it, using file name. If I use file name, it reads that file and saves it to dictionary, so that in the future, if historical data is required for the same file, it does not read it again (it's lazy loading). If no file is supplied to the function, it tries to read file which is given in app settings.
However, for unit testing, I do not want to read any file. Instead, I want it to use small sample of hardcoded historical data. In order to do that, I think, I need to introduce interface to it. Then I can use some IoC to choose between different implementation for unit testing purpose and ordinary launch of application.
Function to get history is given as follows:
public static class Auxiliary
{
private static Dictionary<string, MyData> _myData;
public static MyData GetData(string fileName = null)
{
// ...
}
}
I have created default Unit Test project with Visual Studio so, as far as I know, by default it uses MSTest as test runner and MSUnit as unit testing framework but it does not have any IoC container so I should manage NuGet packages for solution and install Unity.
As far as I know, MSUnit (aka Moles) can unit test static methods (it's unconstrained isolation framework, like Typemock Isolator, unlike NUnit) but still many people suggest not to use any static methods for unit testing.
Should I use shim or stub [URL] Stubs should be used for faking external dependencies and here it is not external library, but my own code.
View 1 Replies
View Related
Apr 16, 2014
I'm new to c++ and boost library also. I need to test a function of my library. For example
// Functions.hpp
int add(const int x, const int y);
//Functions.cpp
int add(const int x, const int y)
{
return (x + y);
}
Now i need to test add function using boost. I need the result or output in below style. What all settings do i need to do in VS 2010 and how i should include boost test in the project.
==== Run unit tests ====
Running 2 test cases...
./mytest.cpp(13): error in "SimpleTestInMainTestingModule": check 1 == 2 failed
Test suite "Master Test Suite" failed with:
1 assertion out of 2 passed
1 assertion out of 2 failed
1 test case out of 2 passed
1 test case out of 2 failed
View 1 Replies
View Related
Jun 17, 2014
I have a question, how can I check if a program is running using c++? For example
if (notepad.exe is running) {
.... ..... ....
View 3 Replies
View Related
May 22, 2013
I have created a shared object in Ubuntu (libMYLIB.so). I am now trying to compile a simple test program (testmylib.c) to see if the shared object is properly built. I am getting an error that the build cannot find the shared object. My build command is:
gcc -lm -l /dir/mylib -lMYLIB.so -o testmylib testmylib.c
where /dir/mylib is where my source and libMYLIB.so reside.
What am I doing wrong?
View 9 Replies
View Related
Feb 21, 2014
I am reading the book C Programming Language. On Structures, it says:
"The only legal operations on a structure are copying it or assigning to it as a unit, taking its address with &, and accessing its members."
What does it mean assigning a structure as a unit?
View 12 Replies
View Related
Apr 3, 2013
How to Install CPPUnit in Solaris? I don't have gcc in Solaris and all the packages I have downloaded for CPPUnit needs gcc to be compiled.
View 4 Replies
View Related
Jan 25, 2014
I have a question about the exact time units returned by the GetProcessTimes function from the Windows API. Is it in seconds or some other unit?
View 3 Replies
View Related
Mar 13, 2015
I am currently trying to send a x264 nal unit using WINSOCK with a reliable multicast socket. It isn't decoding properly, and my initial thought is I am not receiving all the bytes correctly. I was hoping some fresh eyes can provide insight on errors or any improvements. I have seen some topics about this subject, and they showed sending entire structs with the socket. However, I am concerned about endianess so I am trying to stay away from that approach. I have commented out the decoding part, until I am confident that I am receiving the nal unit properly.
Server:
#include <WinSock2.h>
#include <WS2tcpip.h>
#include "wsrm.h"
#include <Windows.h>
#include <stdio.h>
#include <stdint.h>
#include <iostream>
#include "x264Encoder.h"
View 4 Replies
View Related
Oct 18, 2014
I have implemented the IRepository and UnitOfWork Patterns in my project and I have made a little tweak in the UnitOfWork pattern .
public class UnitOfWork : IDisposable {
private DataContext m_Context = new DataContext();
private bool m_disposed = false;
#region Repositories
private GenericRepository<Product> m_ProductRepository = null;
private List<object> m_RepositoryList = new List<object>();
#endregion
[Code] ....
In my UOW class I have the public property ProductRepository. Now my idea was instead of creating a public property for every repository that I have, I created the generic method GetRepository<T> to dynamically create repositories.
Do you think that this change will have bad side effects. I think that it will improve the maintainability of the code.
View 1 Replies
View Related
Jul 21, 2013
I need a random unit vectors in n-dimensional space. how to build it in C++?
View 6 Replies
View Related
May 4, 2013
How can we build unit-tests for functions of libraries, those with user-defined types used as their arguments ?
For example
CRecord func(Myclass * class, BSTR * name, CComptr<xxx> & something);
View 9 Replies
View Related
Feb 8, 2014
I am trying to write a unit convertor for converting temperatures Celsius, Kelvin and Fahrenheit.
Code:
if (select_one == 't' || select_one == 'T'){// this one works perfectly...
//This section does not tell you the use of variables.
//The use of variables can be seen as comments in the main program
[Code].....
This part of code will be part of a larger Unit Converter program. Do you think this method of conversion is wise? The error codes are for debugging use only.
I convert all temperatures of all units, whether Celsius, Kelvin or Farhenheit into Celsius and then convert it into the units the user wants.
For example:
Kelvin -----> Celsius ------------------> Farhenheit
(Input) (base of conversion) (desired output unit)
Do you think this type of conversion is okay?
View 1 Replies
View Related
Jan 17, 2014
I've been reading about libraries; How to make them, how to use them, the different types of libraries, etc..
When using a shared library, does the program require that library to be installed on the computer after the program has been compiled into an .exe?
Ie.. if somebody downloaded a "Helloworld.exe" that I had compiled on my computer using a shared library (that wasn't part of a standard operating system), would they also need that shared library on their computer for the program to run without errors?
and for Static Libraries, when I compile a program using a static library, does it include in the final binary only the functions of the library that are actually used, or does the compiler add in the entire library?
View 8 Replies
View Related
Feb 27, 2013
I have a multidimensional array that runs parallel with a string array
Lincoln 120 300 400
Parks 100 500 250
Shakespeare 0 30 50
Ghandi 250 100 40
Ashe 300 50 175
Rodriguez 87 118 320
Curie 284 0 112
I need to sort this and I know how to do it. But I need to sort it again with the highest value in the first row and keep all information in that row paired with the name . So
Lincoln 120 300 400
Parks 100 500 250
Parks 100 500 250
Lincoln 120 300 400
I need so swap this whole rows. I'm using dynamic array. So my question is Do I have to do a bunch of temps to move them? Or is there a way to move the whole int array row as a single unit?
View 3 Replies
View Related
Sep 19, 2013
I usually check if a bit is set using:
Code: bit = (number >> n) & 1; where `n` is the bit I want to check...
But I came across a stackoverflow answer saying:
bit = number & (1 << x); will not put the value of bit x into bit unless bit has type _Bool (<stdbool.h>).
Otherwise, bit = !!(number & (1 << x)); will..
So why is this? why the double !?
View 5 Replies
View Related
Nov 4, 2013
Everything seems to be correct from my perspective. heres the program: Code: /*c program to check whether a string is palindrome or not*/
#include<stdio.h>
#include<string.h>
int main(void) {
char str[30];
int i,j,flag=0;
[Code] .....
View 1 Replies
View Related
Dec 8, 2013
The reason being is that it says that my program is right
Code:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define NFlights 10
struct date {
int month;
int day;
int year;
int hour;
int minute;
[Code] ....
View 6 Replies
View Related
Jun 15, 2013
Q. In context of C language syntax checking, which of the following can be modeled using Finite Automata?
(A) Detecting proper termination of an instruction.
(B) Detecting balance of parentheses.
(C) Detecting initialization of a variable.
(D) None of the above.
View 4 Replies
View Related
Jan 31, 2015
I am new to C++ , i want to know how to check if a key with modifier is pressed.
When I use GetAsyncKeyState() it gives me error identifier not found.
View 1 Replies
View Related
Aug 4, 2013
I think I may have found a new way of checking for 3d polygon collisions, but I'm not sure. The method involves...
1. finding the planes that the primitives lie on
2. finding the line where the planes intersect
3. if both polys have points on both sides of the line AND have points that overlap on the 1d space of the line, then they intersect.
I have some half done code testing this, and so far it seems to be sound and fairly fast. These are some average time-tests done on my machine for each part:
1. 30 microseconds (both)
2. 7 microseconds
3. TBD
View 5 Replies
View Related
Jul 20, 2014
How would I go about checking for deallocated memory?
For example, let's take this into consideration:
// Unsigned 32-bit / 64-bit integer: uint32, uint64
uint32* Pointer = new uint32[ Size ];
uint64 MemAddr = ( uint64 ) Pointer;
delete[] Pointer;
The above code would proceed to create a new array, store it in a pointer and retrieve the memory address of the array before finally deleting the array.
So let's assume we re-build the pointer and try to access the now deallocated array:
Pointer = ( uint32* ) MemAddr;
Pointer[ 0 ] = 0;
Based on the above snippets of code, how would I check "Pointer" after rebuilding the memory to check if the rebuilt memory has actually been deallocated. Without a check we'd get an exception error.
A bit of detail on why I am trying this:
Before thinking up how to do this, I was storing the addresses in a list and check the list for the addresses to see if they existed or not. However this requires an O(n) search, which isn't exactly what I am wanting. So instead if I used a check for deallocation method, I can go for an O(1) time check and reduce the total time it would take to check for memory allocation/deallocation.
View 11 Replies
View Related
Jan 23, 2014
I have created a prompt which prompts the user for an integer and I have set up a loop to check for if it is an integer or not. My "bug" is that a user can enter an "integer" and "space" and "enter" and it does not give any error and assumes that "All is FINE!". I have gotten the value from the ascii table of 'SPACE' and put it as a check in my parameter of while, but it does not work.
Here is my code:
int x, y, boolean, i;
char buff[256];
printf("Enter the first integer value: ");
scanf("%s", buff);
i = 0;
boolean = 0; //initializing our boolean var that will eventually decide if we have an error or not
[code]....
View 4 Replies
View Related
Mar 6, 2014
Suppose you have a templated class, such as
template <typename T>
class Matrix {
// some stuff and some methods
};
and let's say that you have some methods that need to do some type-dependent stuff, like, for example,
template <typename T>
Matrix<T> Matrix<T>::transpose() const {
// get this->rowCount, this->columnCount
// create a Matrix that has rowCount amount of columns and columnCount amount of rows
// copy (*this)[j][k] to theMatrix[k][j] (for all of the entries in *this)
// if the entries are complex, take the complex conjugate of them all
}
Would it be good practice to check explicitly for the typename parameter (or is this, somehow, defeating the purpose of templates)? std::cout << "I know that this is a design question, but it needs to be asked... ";
View 1 Replies
View Related
Mar 1, 2015
I'm playing around with parts of code and am coming across some errors. Most of my concern is related to strtok(). I've used it before but with a char* named token. I used a while loop to continuously check whether token was equal to NULL. In the following code, however, there aren't any checks. I was wondering if that is why this code prints (null) while running. Also, I would like to know if it is possible to read input like this code attempts to do - assigning tokens to each variable one after the other.
The format of the input:
Zucchini, Squash, pound
Yellow, Squash, pound
Tomatoes, Ugly Ripe, each
#include <stdio.h>
#include <stdlib.h>
[code]....
View 3 Replies
View Related
Oct 13, 2013
Assuming I have a list of pointers to a generic type T:
#include <vector>
//...
list<T*> myList;
Now assuming I want to go on the list, and if T's type is matched to the type I'm looking for, then cast it to this type and do something. List shown here:
list<T*>:: const_iterator iter= myList.begin();
for(; iter!=myList.end(); ++iter){
if( typeid(*iter)==typeid(Something*)) //RUN-TIME ERROR
dynamic_cast<Something*>(*iter)->DoSomething();
}
how do I fix this run-time error?
View 1 Replies
View Related