testMath.cc File Reference
#include "squid.h"
#include "base/Optional.h"
#include "compat/cppunit.h"
#include "SquidMath.h"
#include "unitTestMain.h"
Include dependency graph for testMath.cc:

Go to the source code of this file.

Classes

class  TestMath
 
class  SuccessSumTester< S >
 
class  OverflowSumTester< S >
 

Functions

 CPPUNIT_TEST_SUITE_REGISTRATION (TestMath)
 
template<typename S >
static S RawSum ()
 ends argument recursion for RawSum() with parameters More...
 
template<typename S , typename A , typename... Args>
static S RawSum (A a, Args... args)
 
template<typename S , template< typename > class Tester, typename A , typename B >
static void TestWithZeros (const A a, const B b)
 checks that the summation outcome is unaffected by (not) adding zeros More...
 
template<typename S , template< typename > class Tester, typename A , typename B >
static void TestOrder (const A a, const B b)
 checks that the summation outcome is unaffected by the order of operands More...
 
template<typename A , typename B >
static void TestOverflowForEitherSummationType (const A a, const B b)
 checks that a+b and similar sums overflow for summation types A and B More...
 
template<typename A , typename B >
static void TestSuccessForFirstSummationType (const A a, const B b)
 
template<typename A , typename... Args, typename S = A>
static S GoodSum (const A a, Args... args)
 
template<typename A >
static std::string TypeToString ()
 
template<typename A >
static std::string OperandToString (const A a)
 
template<typename S , typename A , typename B >
static std::string SumToString (const A a, const B b)
 
template<typename S , typename A , typename B , typename C >
static std::string SumToString (const A a, const B b, const C c)
 

Variables

static const auto min64s = std::numeric_limits<int64_t>::min()
 
static const auto min8s = std::numeric_limits<int8_t>::min()
 
static const auto zero8s = int8_t(0)
 
static const auto zero8u = uint8_t(0)
 
static const auto zero64s = int64_t(0)
 
static const auto zero64u = uint64_t(0)
 
static const auto one8s = int8_t(1)
 
static const auto one8u = uint8_t(1)
 
static const auto one64s = int64_t(1)
 
static const auto one64u = uint64_t(1)
 
static const auto max8s = std::numeric_limits<int8_t>::max()
 
static const auto max8u = std::numeric_limits<uint8_t>::max()
 
static const auto max64s = std::numeric_limits<int64_t>::max()
 
static const auto max64u = std::numeric_limits<uint64_t>::max()
 

Function Documentation

◆ CPPUNIT_TEST_SUITE_REGISTRATION()

CPPUNIT_TEST_SUITE_REGISTRATION ( TestMath  )

◆ GoodSum()

template<typename A , typename... Args, typename S = A>
static S GoodSum ( const A  a,
Args...  args 
)
static
Returns
successful a+b value using summation type S (which defaults to A)

Definition at line 191 of file testMath.cc.

References SuccessSumTester< S >::Test().

Referenced by TestMath::testNaturalSum().

◆ OperandToString()

template<typename A >
static std::string OperandToString ( const A  a)
static

Definition at line 58 of file testMath.cc.

Referenced by SumToString(), and SuccessSumTester< S >::Test().

◆ RawSum() [1/2]

template<typename S >
static S RawSum ( )
static

Definition at line 82 of file testMath.cc.

◆ RawSum() [2/2]

template<typename S , typename A , typename... Args>
static S RawSum ( A  a,
Args...  args 
)
static

helper function to add up an arbitrary number of arbitrary-type integers while converting every number to type S and ignoring any under/overflows

Definition at line 91 of file testMath.cc.

◆ SumToString() [1/2]

template<typename S , typename A , typename B >
static std::string SumToString ( const A  a,
const B  b 
)
static

Definition at line 65 of file testMath.cc.

References OperandToString().

◆ SumToString() [2/2]

template<typename S , typename A , typename B , typename C >
static std::string SumToString ( const A  a,
const B  b,
const C  c 
)
static

Definition at line 72 of file testMath.cc.

References OperandToString().

◆ TestOrder()

template<typename S , template< typename > class Tester, typename A , typename B >
static void TestOrder ( const A  a,
const B  b 
)
static

Definition at line 163 of file testMath.cc.

◆ TestOverflowForEitherSummationType()

template<typename A , typename B >
static void TestOverflowForEitherSummationType ( const A  a,
const B  b 
)
static

Definition at line 172 of file testMath.cc.

Referenced by TestMath::testNaturalSum().

◆ TestSuccessForFirstSummationType()

template<typename A , typename B >
static void TestSuccessForFirstSummationType ( const A  a,
const B  b 
)
static

checks that a+b and similar sums succeed for summation type A but overflow for summation type B

Definition at line 182 of file testMath.cc.

Referenced by TestMath::testNaturalSum().

◆ TestWithZeros()

template<typename S , template< typename > class Tester, typename A , typename B >
static void TestWithZeros ( const A  a,
const B  b 
)
static

Definition at line 142 of file testMath.cc.

References zero64s, zero64u, zero8s, and zero8u.

◆ TypeToString()

template<typename A >
static std::string TypeToString ( )
static

helper functions to convert NaturalSum<S>(a,b,...) calls to strings

Definition at line 50 of file testMath.cc.

References A.

Variable Documentation

◆ max64s

const auto max64s = std::numeric_limits<int64_t>::max()
static

Definition at line 41 of file testMath.cc.

Referenced by TestMath::testNaturalSum().

◆ max64u

const auto max64u = std::numeric_limits<uint64_t>::max()
static

Definition at line 42 of file testMath.cc.

Referenced by TestMath::testNaturalSum().

◆ max8s

const auto max8s = std::numeric_limits<int8_t>::max()
static

Definition at line 39 of file testMath.cc.

Referenced by TestMath::testNaturalSum().

◆ max8u

const auto max8u = std::numeric_limits<uint8_t>::max()
static

Definition at line 40 of file testMath.cc.

Referenced by TestMath::testNaturalSum().

◆ min64s

const auto min64s = std::numeric_limits<int64_t>::min()
static

bit-width-specific integers, for developer convenience and code readability

Definition at line 29 of file testMath.cc.

Referenced by TestMath::testNaturalSum().

◆ min8s

const auto min8s = std::numeric_limits<int8_t>::min()
static

Definition at line 30 of file testMath.cc.

Referenced by TestMath::testNaturalSum().

◆ one64s

const auto one64s = int64_t(1)
static

Definition at line 37 of file testMath.cc.

Referenced by TestMath::testNaturalSum().

◆ one64u

const auto one64u = uint64_t(1)
static

Definition at line 38 of file testMath.cc.

Referenced by TestMath::testNaturalSum().

◆ one8s

const auto one8s = int8_t(1)
static

Definition at line 35 of file testMath.cc.

Referenced by TestMath::testNaturalSum().

◆ one8u

const auto one8u = uint8_t(1)
static

Definition at line 36 of file testMath.cc.

Referenced by TestMath::testNaturalSum().

◆ zero64s

const auto zero64s = int64_t(0)
static

Definition at line 33 of file testMath.cc.

Referenced by TestMath::testNaturalSum(), and TestWithZeros().

◆ zero64u

const auto zero64u = uint64_t(0)
static

Definition at line 34 of file testMath.cc.

Referenced by TestMath::testNaturalSum(), and TestWithZeros().

◆ zero8s

const auto zero8s = int8_t(0)
static

Definition at line 31 of file testMath.cc.

Referenced by TestMath::testNaturalSum(), and TestWithZeros().

◆ zero8u

const auto zero8u = uint8_t(0)
static

Definition at line 32 of file testMath.cc.

Referenced by TestMath::testNaturalSum(), and TestWithZeros().

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors