File: testvector.cpp

package info (click to toggle)
kst 2.0.8-6
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 30,748 kB
  • sloc: cpp: 97,086; ansic: 13,364; python: 2,970; sh: 761; yacc: 184; lex: 143; makefile: 141; javascript: 122; perl: 30; xml: 30
file content (74 lines) | stat: -rw-r--r-- 2,204 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/***************************************************************************
 *                                                                         *
 *   copyright : (C) 2007 The University of Toronto                        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "testvector.h"

#include <vector.h>
#include <datacollection.h>
#include <objectstore.h>

#include "ksttest.h"

static Kst::ObjectStore _store;



void TestVector::cleanupTestCase() {
  _store.clear();
}

void TestVector::testVector() 
{
  Kst::VectorPtr v1 = Kst::kst_cast<Kst::Vector>(_store.createObject<Kst::Vector>());

  QCOMPARE(v1->length(), 1);
  QCOMPARE(v1->value(0), &Kst::NOPOINT);

  Q_ASSERT(v1);
  v1->resize(15);
  QCOMPARE(v1->length(), 15);
  v1->zero();
  for (int i = 0; i < 15; ++i) {
    QCOMPARE(v1->value()[i], 0.0);
  }
  QVERIFY(!v1->isScalarList());
  v1->value()[0] = -42;
  v1->resize(3);
  QCOMPARE(v1->length(), 3);
  QCOMPARE(v1->value()[0], -42.0);

  Kst::VectorPtr v2 = Kst::kst_cast<Kst::Vector>(_store.createObject<Kst::Vector>());
  Q_ASSERT(v2);
  QCOMPARE(v2->length(), 1);
  v2 = Kst::kst_cast<Kst::Vector>(_store.createObject<Kst::Vector>());
  v2->resize(1);
  QCOMPARE(v2->length(), 1);
  v2 = Kst::kst_cast<Kst::Vector>(_store.createObject<Kst::Vector>());
  v2->resize(2);
  QCOMPARE(v2->length(), 2);

  v2->resize(3);
  double *data = v2->value();
  data[0] = 1;
  data[1] = 2;
  data[2] = 3;
  QCOMPARE(v2->interpolate(0, 5), 1.0);
  QCOMPARE(v2->interpolate(1, 5), 1.5);
  QCOMPARE(v2->interpolate(2, 5), 2.0);
  QCOMPARE(v2->interpolate(3, 5), 2.5);
  QCOMPARE(v2->interpolate(4, 5), 3.0);
}

#ifdef KST_USE_QTEST_MAIN
QTEST_MAIN(TestVector)
#endif

// vim: ts=2 sw=2 et