test/dim_test.cc
author Alpar Juttner <alpar@cs.elte.hu>
Sat, 22 Dec 2007 07:01:20 +0000
changeset 12 435bbc8127b3
child 14 8685efdef52f
permissions -rw-r--r--
A better way of generating pareto distr, and swap its parameters.

- Pareto distribution is now generated as a composition of a Gamma and
an exponential one
- Similarly to gamma() and weibull(), the shape parameter became the first one.
alpar@8
     1
/* -*- C++ -*-
alpar@8
     2
 *
alpar@8
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@8
     4
 *
alpar@8
     5
 * Copyright (C) 2003-2007
alpar@8
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@8
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@8
     8
 *
alpar@8
     9
 * Permission to use, modify and distribute this software is granted
alpar@8
    10
 * provided that this copyright notice appears in all copies. For
alpar@8
    11
 * precise terms see the accompanying LICENSE file.
alpar@8
    12
 *
alpar@8
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@8
    14
 * express or implied, and with no claim as to its suitability for any
alpar@8
    15
 * purpose.
alpar@8
    16
 *
alpar@8
    17
 */
alpar@8
    18
alpar@8
    19
#include <lemon/dim2.h>
alpar@8
    20
#include <iostream>
alpar@8
    21
#include "test_tools.h"
alpar@8
    22
alpar@8
    23
using namespace std;
alpar@8
    24
using namespace lemon;
alpar@8
    25
int main()
alpar@8
    26
{
alpar@8
    27
alpar@8
    28
  cout << "Testing classes `dim2::Point' and `dim2::BoundingBox'." << endl;
alpar@8
    29
alpar@8
    30
  typedef dim2::Point<int> Point;
alpar@8
    31
	
alpar@8
    32
  Point seged;
alpar@8
    33
  check(seged.size()==2, "Wrong vector addition");
alpar@8
    34
alpar@8
    35
  Point a(1,2);
alpar@8
    36
  Point b(3,4);
alpar@8
    37
alpar@8
    38
  check(a[0]==1 && a[1]==2, "Wrong vector addition");
alpar@8
    39
alpar@8
    40
  seged = a+b;
alpar@8
    41
  check(seged.x==4 && seged.y==6, "Wrong vector addition");
alpar@8
    42
alpar@8
    43
  seged = a-b;
alpar@8
    44
  check(seged.x==-2 && seged.y==-2, "a-b");
alpar@8
    45
alpar@8
    46
  check(a.normSquare()==5,"Wrong norm calculation");
alpar@8
    47
  check(a*b==11, "a*b");
alpar@8
    48
alpar@8
    49
  int l=2;
alpar@8
    50
  seged = a*l;
alpar@8
    51
  check(seged.x==2 && seged.y==4, "a*l");
alpar@8
    52
alpar@8
    53
  seged = b/l;
alpar@8
    54
  check(seged.x==1 && seged.y==2, "b/l");
alpar@8
    55
alpar@8
    56
  typedef dim2::BoundingBox<int> BB;
alpar@8
    57
  BB doboz1;
alpar@8
    58
  check(doboz1.empty(), "It should be empty.");
alpar@8
    59
	
alpar@8
    60
  doboz1.add(a);
alpar@8
    61
  check(!doboz1.empty(), "It should not be empty.");
alpar@8
    62
  doboz1.add(b);
alpar@8
    63
alpar@8
    64
  check(doboz1.bottomLeft().x==1 && 
alpar@8
    65
        doboz1.bottomLeft().y==2 &&
alpar@8
    66
        doboz1.topRight().x==3 && 
alpar@8
    67
        doboz1.topRight().y==4,  
alpar@8
    68
        "added points to box");
alpar@8
    69
alpar@8
    70
  seged.x=2;seged.y=3;
alpar@8
    71
  check(doboz1.inside(seged),"It should be inside.");
alpar@8
    72
alpar@8
    73
  seged.x=1;seged.y=3;
alpar@8
    74
  check(doboz1.inside(seged),"It should be inside.");
alpar@8
    75
alpar@8
    76
  seged.x=0;seged.y=3;
alpar@8
    77
  check(!doboz1.inside(seged),"It should not be inside.");
alpar@8
    78
alpar@8
    79
  BB doboz2(seged);
alpar@8
    80
  check(!doboz2.empty(),
alpar@8
    81
        "It should not be empty. Constructed from 1 point.");
alpar@8
    82
alpar@8
    83
  doboz2.add(doboz1);
alpar@8
    84
  check(doboz2.inside(seged),
alpar@8
    85
        "It should be inside. Incremented a box with another one.");
alpar@8
    86
}