File indexing completed on 2024-05-19 04:34:09
0001 /*************************************************************************** 0002 * * 0003 * copyright : (C) 2007 The University of Toronto * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 ***************************************************************************/ 0011 0012 #include "testvector.h" 0013 0014 #include <vector.h> 0015 #include <datacollection.h> 0016 #include <objectstore.h> 0017 0018 #include "ksttest.h" 0019 0020 static Kst::ObjectStore _store; 0021 0022 0023 0024 void TestVector::cleanupTestCase() { 0025 _store.clear(); 0026 } 0027 0028 void TestVector::testVector() 0029 { 0030 Kst::VectorPtr v1 = Kst::kst_cast<Kst::Vector>(_store.createObject<Kst::Vector>()); 0031 0032 QCOMPARE(v1->length(), 1); 0033 QCOMPARE(v1->value(0), &Kst::NOPOINT); 0034 0035 Q_ASSERT(v1); 0036 v1->resize(15); 0037 QCOMPARE(v1->length(), 15); 0038 v1->zero(); 0039 for (int i = 0; i < 15; ++i) { 0040 QCOMPARE(v1->value()[i], 0.0); 0041 } 0042 QVERIFY(!v1->isScalarList()); 0043 v1->value()[0] = -42; 0044 v1->resize(3); 0045 QCOMPARE(v1->length(), 3); 0046 QCOMPARE(v1->value()[0], -42.0); 0047 0048 Kst::VectorPtr v2 = Kst::kst_cast<Kst::Vector>(_store.createObject<Kst::Vector>()); 0049 Q_ASSERT(v2); 0050 QCOMPARE(v2->length(), 1); 0051 v2 = Kst::kst_cast<Kst::Vector>(_store.createObject<Kst::Vector>()); 0052 v2->resize(1); 0053 QCOMPARE(v2->length(), 1); 0054 v2 = Kst::kst_cast<Kst::Vector>(_store.createObject<Kst::Vector>()); 0055 v2->resize(2); 0056 QCOMPARE(v2->length(), 2); 0057 0058 v2->resize(3); 0059 double *data = v2->value(); 0060 data[0] = 1; 0061 data[1] = 2; 0062 data[2] = 3; 0063 QCOMPARE(v2->interpolate(0, 5), 1.0); 0064 QCOMPARE(v2->interpolate(1, 5), 1.5); 0065 QCOMPARE(v2->interpolate(2, 5), 2.0); 0066 QCOMPARE(v2->interpolate(3, 5), 2.5); 0067 QCOMPARE(v2->interpolate(4, 5), 3.0); 0068 } 0069 0070 #ifdef KST_USE_QTEST_MAIN 0071 QTEST_MAIN(TestVector) 0072 #endif 0073 0074 // vim: ts=2 sw=2 et