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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [testsuite/] [23_containers/] [bitset/] [operations/] [1.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// 2000-01-15  Anders Widell  <awl@hem.passagen.se>
2
 
3
// Copyright (C) 2000, 2003 Free Software Foundation, Inc.
4
//
5
// This file is part of the GNU ISO C++ Library.  This library is free
6
// software; you can redistribute it and/or modify it under the
7
// terms of the GNU General Public License as published by the
8
// Free Software Foundation; either version 2, or (at your option)
9
// any later version.
10
 
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
// GNU General Public License for more details.
15
 
16
// You should have received a copy of the GNU General Public License along
17
// with this library; see the file COPYING.  If not, write to the Free
18
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19
// USA.
20
 
21
#include <string>
22
#include <set>
23
#include <bitset>
24
#include <testsuite_hooks.h>
25
 
26
static char original_bits[1024];
27
static char left_shifted[1024];
28
static char right_shifted[1024];
29
 
30
char
31
random_bit() {
32
  static long x = 1;
33
  return ((x = (3432L*x + 6789L) % 9973L) & 1) + '0';
34
}
35
 
36
void
37
initialise(size_t size) {
38
  for (size_t i=0; i<size; i++)
39
    original_bits[i] = random_bit();
40
 
41
  original_bits[size] = '\0';
42
  left_shifted[size] = '\0';
43
  right_shifted[size] = '\0';
44
}
45
 
46
void
47
shift_arrays(size_t shift_step, size_t size) {
48
  for (size_t i=shift_step; i<size; i++) {
49
    right_shifted[i] = original_bits[i-shift_step];
50
    left_shifted[size-i-1] = original_bits[size+shift_step-i-1];
51
  }
52
  for (size_t i=0; i<shift_step && i<size; i++) {
53
    right_shifted[i] = '0';
54
    left_shifted[size-i-1] = '0';
55
  }
56
}
57
 
58
template <size_t size>
59
  bool
60
  do_test() {
61
    bool test __attribute__((unused)) = true;
62
 
63
    std::bitset<size> shifted;
64
    std::bitset<size> correct;
65
 
66
    initialise(size);
67
 
68
    //std::bitset<size> original = std::string(original_bits); 
69
    std::bitset<size> original = std::bitset<size> (std::string(original_bits));
70
 
71
    for (size_t shift_step=0; shift_step==0 || shift_step<size; shift_step++) {
72
      shift_arrays(shift_step, size);
73
 
74
      shifted = original;
75
      shifted <<= shift_step;
76
      //correct = std::string(left_shifted);
77
      correct = std::bitset<size> (std::string(left_shifted));
78
      VERIFY( shifted == correct );
79
 
80
      shifted = original;
81
      shifted >>= shift_step;
82
      //correct = std::string(right_shifted);
83
      correct = std::bitset<size> (std::string(right_shifted));
84
      VERIFY( shifted == correct );
85
    }
86
 
87
    return test;
88
  }
89
 
90
bool
91
test01() {
92
  bool test __attribute__((unused)) = true;
93
 
94
  VERIFY( do_test<32>() );
95
  VERIFY( do_test<48>() );
96
  VERIFY( do_test<64>() );
97
 
98
  VERIFY( do_test<511>() );
99
  VERIFY( do_test<513>() );
100
  VERIFY( do_test<997>() );
101
  return test;
102
}
103
 
104
int
105
main()
106
{
107
  test01();
108
  return 0;
109
}

powered by: WebSVN 2.1.0

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