Вот есть код для С++ Builder 12, который строит полилинию (фигуру) и определяет по…
- User
Вот есть код для С++ Builder 12, который строит полилинию (фигуру) и определяет по клику, находится ли точка клика внутри или снаружи фигуры. Нужно написать код юнитеста, который брал бы функции уже существующие и написанные в коде и проверял их на исходных данных, к которым результат уже известен другим методом. (пример - проверка площади окружности, зная координаты центра и радиуса нахождение площади, которую сравнивают с значением расчитанной другим способом этой же площади. Если отличается, то ложь). //---------------------------------------------------------------------------
#ifndef Unit1H #define Unit1H //--------------------------------------------------------------------------- #include <System.Classes.hpp> #include <Vcl.Controls.hpp> #include <Vcl.StdCtrls.hpp> #include <Vcl.Forms.hpp> #include <Vcl.ExtCtrls.hpp> #include <Vcl.Dialogs.hpp> #include //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TPaintBox *PaintBox1; TOpenDialog *OpenDialog1; TButton *Button1; void __fastcall PaintBox1Click(TObject *Sender); void __fastcall Button1Click(TObject Sender); private: // User declarations double scale = 7; double centerX = PaintBox1->Width / 2; double centerY = PaintBox1->Height / 2; public: // User declarations __fastcall TForm1(TComponent Owner); }; struct point { double x, y; };
struct triangle { double Vertex1, Vertex2, Vertex3; };
std::vector<std::vector> polylines;
class CalculationNormal { public: double dx, dy, length, direction; void Calculation (double x1, double x2, double y1, double y2, double &normal_x, double &normal_y); };
//--------------------------------------------------------------------------- extern PACKAGE TForm1 Form1; //--------------------------------------------------------------------------- #endif а в Unit1.cpp : > Yuriy: //--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include <math.h> #include #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource ".dfm" TForm1 Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void CalculationNormal::Calculation(double x1, double x2, double y1, double y2, double &normal_x, double &normal_y) { dx = x2 - x1; dy = y2 - y1; length = sqrt(dx * dx + dy * dy); normal_x = - dy / length; normal_y = dx / length; direction = (x1 + x2) / 2 * normal_x + (y1 + y2) / 2 * normal_y; if (direction < 0) { normal_x = -normal_x; normal_y = -normal_y; } }
//--------------------------------------------------------------------------- bool intersect(const point& Point, const point& point1, const point& point2) { if ((point1.y > Point.y && point2.y <= Point.y) || (point2.y > Point.y && point1.y <= Point.y)) { double t = (Point.y - point1.y) / (point2.y - point1.y); if (t >= 0 && t <= 1) { double x_intersect = point1.x + t * (point2.x - point1.x); if (x_intersect >= Point.x) { return true; } } } return false; }
- Assistant
- User
- Assistant
- User
Теперь сделай так, чтобы ошибки выводились не в сообщения, а в текстовый файл
- Assistant
Конечно! Ниже пример, как изменить функцию
RunTests(), чтобы ошибки и итоговый результат выводились не черезShowMessage, а в текстовый файл (например,TestResults.txt), лежащий в каталоге с приложением.