test/polynomial_test.cc
author deba
Mon, 07 May 2007 08:49:57 +0000
changeset 2439 3f1c7a6c33cd
parent 2207 75a29ac69c19
child 2553 bfced05fa852
permissions -rw-r--r--
Modified start() function in Dfs and Dijkstra classes to give back reached
edge/node.

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