source: trunk/test/colour_test.cc @ 919

Last change on this file since 919 was 919, checked in by Jari Häkkinen, 13 years ago

Addresses #75. Colours are dynamically assigned to authors. Removed white from the colour map.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1// $Id: colour_test.cc 919 2009-11-30 23:03:31Z jari $
2
3/*
4  Copyright (C) 2009 Jari Häkkinen
5
6  This file is part of svndigest, http://dev.thep.lu.se/svndigest
7
8  svndigest is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12
13  svndigest is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "Colours.h"
23
24#include <iostream>
25#include <sstream>
26
27int main(int argc, char* argv[])
28{
29  using namespace theplu::svndigest;
30  bool ok=true;
31
32  // The loop adds new authors to the author colour map until all
33  // colours are use. The colour map contains 12 colours and black
34  // (total 13). The loop is 14 iterations and therefore the first
35  // colour is reused for the last author. This test checks that
36  // colours are reused. If the colour map size changes, then the loop
37  // must be adjusted accordingly
38  unsigned char r_first, g_first, b_first;
39  unsigned char r, g, b;
40  for (unsigned int i=0; i<14; ++i) {
41    std::stringstream ss;
42    ss << i;
43    Colours::instance().get_colour(ss.str(), r, g, b);
44    if (!i) r_first=r, g_first=g, b_first=b;  // remember first colour
45  }
46  // Test first and last colour, expected to be the same.
47  if (r!=r_first || g!=g_first || b!=b_first) {
48    ok=false;
49    std::cerr << "Expected r,g,b "
50              << static_cast<int>(r_first) << ','
51              << static_cast<int>(g_first) << ','
52              << static_cast<int>(b_first) << std::endl;
53    std::cerr << "     got r,g,b "
54              << static_cast<int>(r) << ','
55              << static_cast<int>(g) << ','
56              << static_cast<int>(b) << std::endl;
57  }
58
59  if (ok)
60    return 0;
61  return -1;
62}
Note: See TracBrowser for help on using the repository browser.