github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/tests/class.cpp.todo (about)

     1  #include "tests.h"
     2  
     3  //--------------------------
     4  class person {
     5  public:
     6      float name;
     7      int number;
     8  };
     9  
    10  void simple()
    11  {
    12  	person obj;
    13  	obj.name = 2.3;
    14  	obj.number = 4;
    15  
    16  	is_eq(obj.name,2.3);
    17  	is_eq(obj.number,4);
    18  }
    19  /*
    20  //--------------------------
    21  class Rectangle {
    22      int width, height;
    23    public:
    24      Rectangle ();
    25      int area() {return width*height;}
    26  };
    27  
    28  Rectangle::Rectangle () {
    29    width = 4;
    30    height = 5;
    31  }
    32  
    33  void default_constructor()
    34  {
    35  	Rectangle rec;
    36  	is_eq(rec.area(),20);
    37  }
    38  
    39  //--------------------------
    40  class Rectangle2 {
    41      int width, height;
    42    public:
    43      Rectangle2 (int,int);
    44      int area() {return width*height;}
    45  };
    46  
    47  Rectangle2::Rectangle2 (int a, int b) {
    48    width = a;
    49    height = b;
    50  }
    51  
    52  void constructor()
    53  {
    54  	Rectangle2 rec(2,3);
    55  	is_eq(rec.area(),6);
    56  }
    57  
    58  //--------------------------
    59  class Rectangle3 {
    60      int width, height;
    61    public:
    62      void set_values (int,int);
    63      int area() {return width*height;}
    64  };
    65  
    66  void Rectangle3::set_values (int x, int y) {
    67    width = x;
    68    height = y;
    69  }
    70  
    71  void setter()
    72  {
    73  	Rectangle3 rec;
    74  	rec.set_values(4,5);
    75  	is_eq(rec.area(),20);
    76  }
    77  
    78  
    79  //--------------------------
    80  class Rectangle4 {
    81      int width, height;
    82    public:
    83      Rectangle4 (int a ,int b ) {
    84    		width = a;
    85    		height = b;
    86  	}
    87      int area() {return width*height;}
    88  };
    89  
    90  void constructor2()
    91  {
    92  	Rectangle4 rec(2,3);
    93  	is_eq(rec.area(),6);
    94  }
    95  
    96  
    97  //--------------------------
    98  class Rectangle5 {
    99      int width, height;
   100    public:
   101      Rectangle5() {};
   102      Rectangle5 (int a ,int b ): width(a), height(b){}
   103      int area() {return width*height;}
   104  };
   105  
   106  void constructor3()
   107  {
   108  	Rectangle5 rec(2,3);
   109  	is_eq(rec.area(),6);
   110  }
   111  */
   112  int main()
   113  {
   114      plan(2);
   115  
   116  	simple();
   117  	// default_constructor();
   118  	// constructor();
   119  	// constructor2();
   120  	// constructor3();
   121  	// setter();
   122  
   123      done_testing();
   124  }