diff --git a/.gitattributes b/.gitattributes index cbf29e8985..a2d647ec30 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2211,6 +2211,9 @@ components/tachart/tasubcomponentseditor.pas svneol=native#text/pascal components/tachart/tatools.pas svneol=native#text/pascal components/tachart/tatransformations.pas svneol=native#text/pascal components/tachart/tatypes.pas svneol=native#text/plain +components/tachart/test/UtilsTest.pas svneol=native#text/pascal +components/tachart/test/test.lpi svneol=native#text/plain +components/tachart/test/test.lpr svneol=native#text/pascal components/tdbf/Makefile svneol=native#text/plain components/tdbf/Makefile.fpc svneol=native#text/plain components/tdbf/dbflaz.lpk svneol=native#text/pascal diff --git a/components/tachart/test/UtilsTest.pas b/components/tachart/test/UtilsTest.pas new file mode 100644 index 0000000000..d66fc2b5d5 --- /dev/null +++ b/components/tachart/test/UtilsTest.pas @@ -0,0 +1,101 @@ +unit UtilsTest; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, FPCUnit, TestRegistry, TAChartUtils; + +type + + { TIntervalListTest } + + TIntervalListTest = class(TTestCase) + private + FIList: TIntervalList; + protected + procedure SetUp; override; + procedure TearDown; override; + published + procedure Basic; + procedure Intersect; + procedure Merge; + end; + + +implementation + +{ TIntervalListTest } + +procedure TIntervalListTest.Basic; +begin + AssertEquals(0, FIList.IntervalCount); + FIList.AddRange(1.0, 2.0); + AssertEquals(1, FIList.IntervalCount); + FIList.AddPoint(3.0); + AssertEquals(2, FIList.IntervalCount); + AssertEquals(3.0, FIList.Interval[1].FEnd); + FIList.Clear; + AssertEquals(0, FIList.IntervalCount); +end; + +procedure TIntervalListTest.Intersect; +var + l, r: Double; + hint: Integer = 0; +begin + FIList.Clear; + FIList.AddRange(1.0, 2.0); + l := 5.0; + r := 6.0; + AssertFalse(FIList.Intersect(l, r, hint)); + l := 1.5; + r := 6.0; + AssertTrue(FIList.Intersect(l, r, hint)); + AssertEquals(2.0, r); + FIList.Epsilon := 0.1; + l := 0.5; + r := 2.5; + AssertTrue(FIList.Intersect(l, r, hint)); + AssertEquals(0.9, l); + AssertEquals(2.1, r); +end; + +procedure TIntervalListTest.Merge; +begin + FIList.Clear; + FIList.AddRange(1.0, 2.0); + FIList.AddRange(3.0, 4.0); + AssertEquals(2, FIList.IntervalCount); + FIList.AddRange(1.5, 2.5); + AssertEquals(2, FIList.IntervalCount); + AssertEquals(2.5, FIList.Interval[0].FEnd); + FIList.AddRange(3.5, 3.6); + AssertEquals(2, FIList.IntervalCount); + FIList.AddRange(2.5, 3.0); + AssertEquals(1, FIList.IntervalCount); + FIList.AddPoint(4.0); + AssertEquals(1, FIList.IntervalCount); + FIList.AddPoint(4.1); + AssertEquals(2, FIList.IntervalCount); +end; + +procedure TIntervalListTest.SetUp; +begin + inherited SetUp; + FIList := TIntervalList.Create; +end; + +procedure TIntervalListTest.TearDown; +begin + inherited TearDown; + FreeAndNil(FIList); +end; + +initialization + + RegisterTests([TIntervalListTest]); + +end. + diff --git a/components/tachart/test/test.lpi b/components/tachart/test/test.lpi new file mode 100644 index 0000000000..a7f36822a0 --- /dev/null +++ b/components/tachart/test/test.lpi @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/tachart/test/test.lpr b/components/tachart/test/test.lpr new file mode 100644 index 0000000000..e3c1fd8b75 --- /dev/null +++ b/components/tachart/test/test.lpr @@ -0,0 +1,67 @@ +program test; + +{$mode objfpc}{$H+} + +uses + {$IFDEF UNIX}{$IFDEF UseCThreads} + cthreads, + {$ENDIF}{$ENDIF} + Classes, SysUtils, CustApp, Interfaces, + FPCUnit, TestReport, TestRegistry, PlainTestReport, UtilsTest; + +type + + { TAChartTests } + + TAChartTests = class(TCustomApplication) + protected + procedure DoRun; override; + public + constructor Create(TheOwner: TComponent); override; + destructor Destroy; override; + end; + +{ TAChartTests } + +procedure TAChartTests.DoRun; +var + testResult: TTestResult = nil; + writer: TPlainResultsWriter = nil; +begin + testResult := TTestResult.Create; + writer := TPlainResultsWriter.Create(nil); + try + testResult.AddListener(writer); + GetTestRegistry.Run(testResult); + writer.WriteResult(testResult); + finally + testResult.Free; + writer.Free; + end; + Terminate; +end; + +constructor TAChartTests.Create(TheOwner: TComponent); +begin + inherited Create(TheOwner); + StopOnException:=True; +end; + +destructor TAChartTests.Destroy; +begin + inherited Destroy; +end; + +var + Application: TAChartTests; + +{$R *.res} + +begin + Application:=TAChartTests.Create(nil); + Application.Title:='TAChart tests'; + Application.Initialize; + Application.Run; + Application.Free; +end. +