monotone

monotone Mtn Source Tree

Root/numeric_vocab.cc

1// Copyright (C) 2006 Nathaniel Smith <njs@pobox.com>
2//
3// This program is made available under the GNU GPL version 2.0 or
4// greater. See the accompanying file COPYING for details.
5//
6// This program is distributed WITHOUT ANY WARRANTY; without even the
7// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8// PURPOSE.
9
10// Currently, this file just contains unit tests for widen<>.
11
12#ifdef BUILD_UNIT_TESTS
13
14#include "base.hh"
15#include "unit_tests.hh"
16#include "sanity.hh"
17#include "numeric_vocab.hh"
18
19UNIT_TEST(widen, widen)
20{
21 // These all have double-parens to stop the C preprocessor from becoming
22 // confused by the commas in the template arguments. The static_cast<u8>'s
23 // are to shut up compiler warnings.
24
25 // unsigned -> unsigned
26 I((widen<u8,u8>(1) == 1));
27 I((widen<u8,u8>(255) == 255));
28 I((widen<u8,u8>(static_cast<u8>(-1)) == 255));
29 I((widen<u32,u8>(1) == 1));
30 I((widen<u32,u8>(255) == 255));
31 I((widen<u32,u8>(static_cast<u8>(-1)) == 255));
32 // unsigned -> signed
33 I((widen<s32,u8>(1) == 1));
34 I((widen<s32,u8>(255) == 255));
35 I((widen<s32,u8>(static_cast<u8>(-1)) == 255));
36 // signed -> signed
37 I((widen<s32,s8>(1) == 1));
38 I((widen<s32,s8>(255) == -1));
39 I((widen<s32,s8>(-1) == -1));
40 // signed -> unsigned ((critical case!))
41 I((widen<u32,s8>(1) == 1));
42 I((widen<u32,s8>(255) == 255));
43 I((widen<u32,s8>(-1) == 255));
44 // contrasts with:
45 I((static_cast<u32>(s8(-1)) == u32(4294967295u)));
46}
47
48#endif // BUILD_UNIT_TESTS
49
50
51// Local Variables:
52// mode: C++
53// fill-column: 76
54// c-file-style: "gnu"
55// indent-tabs-mode: nil
56// End:
57// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
58

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status