blob: 9caaa1fb2bb8547f0d12565129689e5d0a2581cd [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
2 Copyright 2010 Google Inc.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17
18#include "GrClip.h"
19#include "GrTDArray.h"
20#include "GrTBSearch.h"
21#include "GrMatrix.h"
bsalomon@google.com6034c502011-02-22 16:37:47 +000022#include "GrRedBlackTree.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000023
24static void dump(const GrTDArray<int>& array) {
25#if 0
26 for (int i = 0; i < array.count(); i++) {
27 printf(" %d", array[i]);
28 }
29 printf("\n");
30#endif
31}
32
33static void test_tdarray() {
34 GrTDArray<int> array;
bsalomon@google.com6034c502011-02-22 16:37:47 +000035
reed@google.comac10a2d2010-12-22 21:39:39 +000036 *array.append() = 0; dump(array);
37 *array.append() = 2; dump(array);
38 *array.append() = 4; dump(array);
39 *array.append() = 6; dump(array);
40 GrAssert(array.count() == 4);
41
42 *array.insert(0) = -1; dump(array);
43 *array.insert(2) = 1; dump(array);
44 *array.insert(4) = 3; dump(array);
45 *array.insert(7) = 7; dump(array);
46 GrAssert(array.count() == 8);
47 array.remove(3); dump(array);
48 array.remove(0); dump(array);
49 array.removeShuffle(4); dump(array);
50 array.removeShuffle(1); dump(array);
51 GrAssert(array.count() == 4);
52}
53
54static bool LT(const int& elem, int value) {
55 return elem < value;
56}
57static bool EQ(const int& elem, int value) {
58 return elem == value;
59}
60
61static void test_bsearch() {
62 const int array[] = {
63 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99
64 };
65
66 for (size_t n = 0; n < GR_ARRAY_COUNT(array); n++) {
67 for (size_t i = 0; i < n; i++) {
68 int index = GrTBSearch<int, int>(array, n, array[i]);
69 GrAssert(index == i);
70 index = GrTBSearch<int, int>(array, n, -array[i]);
71 GrAssert(index < 0);
72 }
73 }
74}
75
reed@google.comac10a2d2010-12-22 21:39:39 +000076void gr_run_unittests() {
77 test_tdarray();
78 test_bsearch();
reed@google.comac10a2d2010-12-22 21:39:39 +000079 GrMatrix::UnitTest();
bsalomon@google.com6034c502011-02-22 16:37:47 +000080 GrRedBlackTree<int>::UnitTest();
reed@google.comac10a2d2010-12-22 21:39:39 +000081}
82
83