test/polynomial_test.cc
changeset 2176 0f647e65ecad
child 2207 75a29ac69c19
equal deleted inserted replaced
-1:000000000000 0:ad68dc5baa1c
       
     1 /* -*- C++ -*-
       
     2  *
       
     3  * This file is a part of LEMON, a generic C++ optimization library
       
     4  *
       
     5  * Copyright (C) 2003-2006
       
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
       
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
       
     8  *
       
     9  * Permission to use, modify and distribute this software is granted
       
    10  * provided that this copyright notice appears in all copies. For
       
    11  * precise terms see the accompanying LICENSE file.
       
    12  *
       
    13  * This software is provided "AS IS" with no warranty of any kind,
       
    14  * express or implied, and with no claim as to its suitability for any
       
    15  * purpose.
       
    16  *
       
    17  */
       
    18 
       
    19 #include <lemon/polynomial.h>
       
    20 #include <lemon/xy.h>
       
    21 #include <iostream>
       
    22 #include "test_tools.h"
       
    23 
       
    24 using namespace std;
       
    25 using namespace lemon;
       
    26 int main()
       
    27 {
       
    28   Polynomial<int> pi(5);
       
    29   check(pi.deg()==5,"Something is wrong here.");
       
    30   pi[0]=12;
       
    31   pi[5]=3;
       
    32   pi[2]=7;
       
    33   check(pi[1]==0,"Uninitialized elements should be(?) zero.");
       
    34   {
       
    35     Polynomial<double> pd=pi;
       
    36     check(pd.deg()==5,"Something is wrong here.");
       
    37     check(pd[0]==12,"Something is wrong here.");
       
    38     check(pd[5]==3,"Something is wrong here.");
       
    39 
       
    40   }
       
    41 
       
    42   Polynomial<double> pd;
       
    43   pd=pi;
       
    44   check(pd.deg()==5,"Something is wrong here.");
       
    45   check(pd[0]==12,"Something is wrong here.");
       
    46   check(pd[5]==3,"Something is wrong here.");
       
    47 
       
    48   check(pd(0)==12,"Something is wrong here.");
       
    49   check(pd(1)==22,"Something is wrong here.");
       
    50   check(pd(2)==136,"Something is wrong here.");
       
    51 
       
    52   check((pd*pi).deg()==10,"Something is wrong here.");
       
    53   check((pd*pi)[10]==9,"Something is wrong here.");
       
    54   check((pd*pi)[7]==42,"Something is wrong here.");
       
    55 
       
    56   Polynomial<double> pd2=pd+pi;
       
    57   check(pd2[5]==6,"Something is wrong here.");
       
    58   pd2+=pd;
       
    59   pd2+=pi;
       
    60   check(pd2[5]==12,"Something is wrong here.");
       
    61   pd2-=pd;
       
    62   pd2-=pi;
       
    63   check(pd2[5]==6,"Something is wrong here.");
       
    64   check((pd-pi)[5]==0,"Something is wrong here.");
       
    65 
       
    66   Polynomial<double> pdd=pd.derivate();
       
    67   pd.derivateMyself();
       
    68   check(pdd==pd,"Something is wrong here.");
       
    69   check(pd.deg()==4,"Something is wrong here.");
       
    70   check(pd[4]==15,"Something is wrong here.");
       
    71 
       
    72   
       
    73   Polynomial<double> pdi=pd.integrate();
       
    74   pd.integrateMyself();
       
    75   check(pdi==pd,"Something is wrong here.");
       
    76   check(pd.deg()==5,"Something is wrong here.");
       
    77   check(pd[5]==3,"Something is wrong here.");
       
    78   check(pd[0]==0,"Something is wrong here.");
       
    79   
       
    80   
       
    81 }