OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [language/] [cxx/] [ustl/] [current/] [tests/] [bvt17.cpp] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// 011010011001011001011000100100
2
// This file is part of the uSTL library, an STL implementation.
3
//
4
// Copyright (c) 2005-2009 by Mike Sharov <msharov@users.sourceforge.net>
5
// This file is free software, distributed under the MIT License.
6
 
7
#include "stdtest.h"
8
 
9
size_t SizeOfSet (const bitset<30>& v)
10
{
11
    return (stream_size_of (v));
12
}
13
 
14
void TestBitset (void)
15
{
16
    bitset<30> bs1;
17
    cout.format ("bitset<%zu> bs1: capacity() = %zu, sizeof() = %zu\n", bs1.size(), bs1.capacity(), sizeof(bs1));
18
    cout << bs1 << endl;
19
    bs1.set();
20
    bs1.set (6, false);
21
    cout << bs1 << endl;
22
    bs1.flip();
23
    cout << bs1 << endl;
24
    bs1.flip();
25
    cout << bs1 << endl;
26
 
27
    bs1.reset();
28
    string comment;     // See line 0 in this file
29
    cin >> comment >> bs1;
30
    cout << bs1 << endl;
31
    cout.format ("count = %zu\n", bs1.count());
32
 
33
    bs1.reset();
34
    cout << bs1;
35
    static const char tf[2][6] = { "false", "true" };
36
    cout.format ("\nany = %s, none = %s, count = %zu\n", tf[bs1.any()], tf[bs1.none()], bs1.count());
37
    bs1.flip();
38
    cout << bs1;
39
    cout.format ("\nany = %s, none = %s, count = %zu\n", tf[bs1.any()], tf[bs1.none()], bs1.count());
40
    bs1.reset();
41
    bs1.set (4);
42
    bs1.set (7);
43
    bs1.set (8);
44
    cout << bs1;
45
    cout.format ("\ntest(7) == %s, [9] = %s, [8] = %s", tf[bs1.test(7)], tf[bs1[9]], tf[bs1[8]]);
46
    cout.format ("\nany = %s, none = %s, count = %zu\n", tf[bs1.any()], tf[bs1.none()], bs1.count());
47
    cout << "~bs1 == " << ~bs1;
48
    cout.format ("\nto_value == 0x%X\n", bs1.to_value());
49
 
50
    bitset<70> bs2 ("0101101");
51
    cout.format ("bitset<%zu> bs2: capacity() = %zu, sizeof() = %zu\n", bs2.size(), bs2.capacity(), sizeof(bs2));
52
    cout << bs2;
53
    bs2.set (34, 40, 13);
54
    cout << "\nbs2.set(34,40,13)\n";
55
    cout << bs2;
56
    cout.format ("\nbs2.at(34,40) = %u\n", bs2.at(34,40));
57
 
58
    bitset<256> bs3 (0x3030);
59
    cout.format ("bitset<%zu> bs3: capacity() = %zu, sizeof() = %zu\n", bs3.size(), bs3.capacity(), sizeof(bs3));
60
    cout.format ("bs3.to_value() == 0x%X\n", bs3.to_value());
61
 
62
    bitset<30> bs4 (bs1);
63
    if (bs1 == bs4)
64
        cout << "bs4 == bs1\n";
65
 
66
    bs4 = 0x50505050;
67
    cout << "bs4 = 0x50505050: " << bs4;
68
    bs1 = 0x30303030;
69
    cout << "\nbs1 = 0x30303030: " << bs1;
70
    bs4 &= bs1;
71
    cout << "\nbs4 &= bs1; bs4 = " << bs4;
72
    bs4 = 0x50505050;
73
    bs4 &= bs1;
74
    cout << "\nbs4 & bs1;  bs4 = " << bs4;
75
    bs4 = 0x50505050;
76
    bs4 |= bs1;
77
    cout << "\nbs4 |= bs1; bs4 = " << bs4;
78
    bs4 = 0x50505050;
79
    bs4 = bs4 | bs1;
80
    cout << "\nbs4 | bs1;  bs4 = " << bs4;
81
    bs4 = 0x50505050;
82
    bs4 ^= bs1;
83
    cout << "\nbs4 ^= bs1; bs4 = " << bs4;
84
    bs4 = 0x50505050;
85
    bs4 = bs4 ^ 0x30303030;
86
    cout << "\nbs4 ^ bs1;  bs4 = " << bs4;
87
 
88
    memblock b (stream_size_of (bs4));
89
    ostream os (b);
90
    os << bs4;
91
    istream is (b);
92
    bs4 = 0;
93
    is >> bs4;
94
    cout.format ("\nstream[%zu];  bs4 = ", b.size());
95
    cout << bs4 << endl;
96
}
97
 
98
StdBvtMain (TestBitset)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.