| 1 | /* -*- mode: C++ -*- */ |
|---|
| 2 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 3 | // FILE : test.tol |
|---|
| 4 | // PURPOSE: GisTools test |
|---|
| 5 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 6 | |
|---|
| 7 | Text email_ = "vdebuen@tol-project.org"; |
|---|
| 8 | Text link_ = ""; |
|---|
| 9 | Text summary_ = "checking matrix row selection"; |
|---|
| 10 | |
|---|
| 11 | //Write here the initial test TOL code if needed |
|---|
| 12 | Real numErr0 = Copy(NError); |
|---|
| 13 | Real numWar0 = Copy(NWarning); |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | #Require GisTools; |
|---|
| 17 | |
|---|
| 18 | Real t1 = Copy(Time); |
|---|
| 19 | Real rndSeed = 0; |
|---|
| 20 | Real data.num = 300000; |
|---|
| 21 | Real class.num = 100; |
|---|
| 22 | |
|---|
| 23 | Matrix Length = Rand(data.num,1,-10000,10000); |
|---|
| 24 | |
|---|
| 25 | WriteLn("Quantile over edge's length ... "); |
|---|
| 26 | Set q.def = Range(1/class.num,1-1/class.num,1/class.num); |
|---|
| 27 | Set q = MatSet(Tra(Quantile(Length, SetCol(q.def))))[1]; |
|---|
| 28 | Real t2 = Copy(Time); |
|---|
| 29 | WriteLn("Quantile time "<<(t2-t1)+" seconds"); |
|---|
| 30 | |
|---|
| 31 | WriteLn("ClassifyColumnByRank over edge's length... "); |
|---|
| 32 | Matrix length.class = GisTools::ClassifyRowsByRank(Length, q); |
|---|
| 33 | Real t3 = Copy(Time); |
|---|
| 34 | WriteLn("ClassifyColumnByRank time "<<(t3-t2)+" seconds"); |
|---|
| 35 | |
|---|
| 36 | Real q.select = IntRand(2,Card(q)-1); |
|---|
| 37 | Set length.select.1 = GisTools::SelectRowsWithValue( |
|---|
| 38 | length.class,q.select-1); |
|---|
| 39 | Set length.select.2 = GisTools::SelectRowsWithValue( |
|---|
| 40 | length.class,q.select); |
|---|
| 41 | Set length.select.3 = GisTools::SelectRowsWithValue( |
|---|
| 42 | length.class,q.select+1); |
|---|
| 43 | Set length.select.4 = GisTools::SelectRowsInInterval( |
|---|
| 44 | length.class,True,q.select-1,q.select+1,True); |
|---|
| 45 | |
|---|
| 46 | Matrix aux.123 = |
|---|
| 47 | { |
|---|
| 48 | Set sel = length.select.1<<length.select.2<<length.select.3; |
|---|
| 49 | SubRow(Length, Sort(sel,Real(Real a, Real b) {Compare(a,b)})) |
|---|
| 50 | }; |
|---|
| 51 | Matrix aux.4 = SubRow(Length, length.select.4); |
|---|
| 52 | |
|---|
| 53 | Real ok.1 = MatMax(Abs(aux.123-aux.4)) == 0; |
|---|
| 54 | |
|---|
| 55 | Real numErr1 = Copy(NError); |
|---|
| 56 | Real numWar1 = Copy(NWarning); |
|---|
| 57 | |
|---|
| 58 | Set partialResults_ = [[numErr0, numErr1, |
|---|
| 59 | ok.1]]; |
|---|
| 60 | |
|---|
| 61 | //This is a messure of the success of the test |
|---|
| 62 | Real quality_ = And(numErr1 == numErr0, |
|---|
| 63 | numWar1 <= numWar0+1, |
|---|
| 64 | ok.1); |
|---|
| 65 | |
|---|
| 66 | //Return the results |
|---|
| 67 | Set resultStr_ = @strTestStatus(summary_, link_, quality_, |
|---|
| 68 | "Partial results = "<<partialResults_, |
|---|
| 69 | "NO DBServerType", "NO DBServerHost", "NO DBAlias", |
|---|
| 70 | email_); |
|---|
| 71 | WriteLn(""<<resultStr_); |
|---|
| 72 | resultStr_; |
|---|
| 73 | |
|---|
| 74 | /* */ |
|---|
| 75 | |
|---|