diff --git a/Configuration/GlobalAssemblyInfo.cs b/Configuration/GlobalAssemblyInfo.cs index 777519197..c92d5fedb 100644 --- a/Configuration/GlobalAssemblyInfo.cs +++ b/Configuration/GlobalAssemblyInfo.cs @@ -15,7 +15,7 @@ internal static class RevisionClass public const string Major = "3"; public const string Minor = "8"; public const string Build = "3"; - public const string Revision = "3134"; + public const string Revision = "3135"; public const string MainVersion = Major + "." + Minor; public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision; diff --git a/Configuration/Version.defs b/Configuration/Version.defs index 4884b82ff..27c828195 100644 --- a/Configuration/Version.defs +++ b/Configuration/Version.defs @@ -1,4 +1,4 @@ -%COREVERSION%=3 -%REVISION%=3134 %MINOR%=8 +%REVISION%=3135 +%COREVERSION%=3 %MAJOR%=3 diff --git a/Release/pabcversion.txt b/Release/pabcversion.txt index f50f40f14..508d7429d 100644 --- a/Release/pabcversion.txt +++ b/Release/pabcversion.txt @@ -1 +1 @@ -3.8.3.3134 +3.8.3.3135 diff --git a/ReleaseGenerators/PascalABCNET_version.nsh b/ReleaseGenerators/PascalABCNET_version.nsh index e5f8d7321..1778b2f55 100644 --- a/ReleaseGenerators/PascalABCNET_version.nsh +++ b/ReleaseGenerators/PascalABCNET_version.nsh @@ -1 +1 @@ -!define VERSION '3.8.3.3134' +!define VERSION '3.8.3.3135' diff --git a/ReleaseGenerators/RebuildStandartModules.pas b/ReleaseGenerators/RebuildStandartModules.pas index ed831acb3..04fbeb55a 100644 --- a/ReleaseGenerators/RebuildStandartModules.pas +++ b/ReleaseGenerators/RebuildStandartModules.pas @@ -15,7 +15,7 @@ ABCDatabases,PT4Databases,BlockFileOfT,Controls, OpenCLABC, OpenCL, OpenGLABC, OpenGL, - BBCMicroBit, School, SF, TwoPanelsWindow, NUnitABC, PlotWPF, XLSX + BBCMicroBit, School, SF, TwoPanelsWindow, NUnitABC, PlotWPF, XLSX, LightPT, Tasks ; begin diff --git a/ReleaseGenerators/sect_Core.nsh b/ReleaseGenerators/sect_Core.nsh index a16e2d290..eb3875fc3 100644 --- a/ReleaseGenerators/sect_Core.nsh +++ b/ReleaseGenerators/sect_Core.nsh @@ -136,6 +136,8 @@ File ..\bin\Lib\School.pcu File ..\bin\Lib\SF.pcu File ..\bin\Lib\Turtle.pcu + File ..\bin\Lib\LightPT.pcu + File ..\bin\Lib\Tasks.pcu File ..\bin\Lib\TwoPanelsWindow.pcu File ..\bin\Lib\NUnitABC.pcu File ..\bin\Lib\PlotWPF.pcu @@ -212,6 +214,8 @@ ${AddFile} "School.pcu" ${AddFile} "SF.pcu" ${AddFile} "Turtle.pcu" + ${AddFile} "LightPT.pcu" + ${AddFile} "Tasks.pcu" ${AddFile} "TwoPanelsWindow.pcu" ${AddFile} "NUnitABC.pcu" ${AddFile} "PlotWPF.pcu" @@ -306,6 +310,8 @@ File ..\bin\Lib\School.pas File ..\bin\Lib\SF.pas File ..\bin\Lib\Turtle.pas + File ..\bin\Lib\LightPT.pas + File ..\bin\Lib\Tasks.pas File ..\bin\Lib\TwoPanelsWindow.pas File ..\bin\Lib\NUnitABC.pas File ..\bin\Lib\PlotWPF.pas @@ -376,6 +382,8 @@ ${AddFile} "School.pas" ${AddFile} "SF.pas" ${AddFile} "Turtle.pas" + ${AddFile} "LightPT.pas" + ${AddFile} "Tasks.pas" ${AddFile} "TwoPanelsWindow.pas" ${AddFile} "NUnitABC.pas" ${AddFile} "PlotWPF.pas" diff --git a/bin/Lib/LightPT.pas b/bin/Lib/LightPT.pas new file mode 100644 index 000000000..a62c27f5c --- /dev/null +++ b/bin/Lib/LightPT.pas @@ -0,0 +1,394 @@ +/// Модуль LightPT автоматической легковесной проверки заданий +unit LightPT; + +uses __RedirectIOMode; + +type + PTException = class(Exception) end; + InputCountException = class(PTException) + Count,n: integer; + constructor (Count,n: integer); + begin + Self.Count := Count; + Self.n := n; + end; + end; + InputCount2Exception = class(InputCountException) + end; + InputTypeException = class(PTException) + n: integer; + ExpectedType, InputType: string; + constructor (n: integer; ExpectedType, InputType: string); + begin + Self.n := n; + Self.ExpectedType := ExpectedType; + Self.InputType := InputType; + end; + end; + TaskStatus = (Completed,NotCompleted,AbsentTask); + +var + OutputString := new StringBuilder; + OutputList := new List; + InputList := new List; + +var Cur := 0; + +function TaskName := ExtractFileName(System.Environment.GetCommandLineArgs[0]).Replace('.exe',''); + +procedure WriteInfoToDatabase(name: string; result: TaskStatus); +begin + try + System.IO.File.AppendAllText('db.txt',$'{name} {dateTime.Now.ToString(''u'')} {Result.ToString}'+#10); + except + on e: Exception do + Print(e.Message); + end; +end; + +procedure CheckInputCount(n: integer); +begin + if InputList.Count < n then + raise new InputCountException(InputList.Count,n) +end; + +procedure CheckInput2Count(i: integer); +begin + if InputList.Count <= i then + raise new InputCount2Exception(InputList.Count,i+1) +end; + +function IsInt(i: integer) := InputList[i] is integer; +function IsRe(i: integer) := InputList[i] is real; +function IsStr(i: integer) := InputList[i] is string; +function IsBoo(i: integer) := InputList[i] is boolean; +function IsChr(i: integer) := InputList[i] is char; + +function Int(i: integer): integer; +begin + CheckInput2Count(i); + if not IsInt(i) then + raise new InputTypeException(i+1,'integer',TypeName(InputList[i])); + Result := integer(InputList[i]); +end; + +function Re(i: integer): real; +begin + CheckInput2Count(i); + if not IsRe(i) then + raise new InputTypeException(i+1,'real',TypeName(InputList[i])); + Result := real(InputList[i]); +end; + +function Str(i: integer): string; +begin + CheckInput2Count(i); + if not IsStr(i) then + raise new InputTypeException(i+1,'string',TypeName(InputList[i])); + Result := string(InputList[i]); +end; + +function Boo(i: integer): boolean; +begin + CheckInput2Count(i); + if not IsBoo(i) then + raise new InputTypeException(i+1,'boolean',TypeName(InputList[i])); + Result := boolean(InputList[i]); +end; + +function Chr(i: integer): char; +begin + CheckInput2Count(i); + if not IsChr(i) then + raise new InputTypeException(i+1,'char',TypeName(InputList[i])); + Result := char(InputList[i]); +end; + +function Int: integer; +begin + Result := Int(Cur); + Cur += 1; +end; + +function Re: real; +begin + Result := Re(Cur); + Cur += 1; +end; + +function Str: string; +begin + Result := Str(Cur); + Cur += 1; +end; + +function Boo: boolean; +begin + Result := Boo(Cur); + Cur += 1; +end; + +function Chr: char; +begin + Result := Chr(Cur); + Cur += 1; +end; + +function Int2: (integer,integer) := (Int,Int); +function Re2: (real,real) := (Re,Re); +function IntArr(n: integer): array of integer := (1..n).Select(x->Int).ToArray; +function ReArr(n: integer): array of real := (1..n).Select(x->Re).ToArray; + +function Random(a, b: integer): integer; +begin + Result := PABCSystem.Random(a,b); + InputList.Add(Result); +end; + +function Random(a, b: real): real; +begin + Result := PABCSystem.Random(a,b); + InputList.Add(Result); +end; + +function Random2(a, b: integer): (integer, integer); +begin + Result := PABCSystem.Random2(a,b); + InputList.Add(Result[0]); + InputList.Add(Result[1]); +end; + +function Random2(a, b: real): (real, real); +begin + Result := PABCSystem.Random2(a,b); + InputList.Add(Result[0]); + InputList.Add(Result[1]); +end; + +function ReadString: string; +begin + Result := PABCSystem.ReadString; + InputList.Add(Result); +end; + +function ReadlnString := ReadString; +function ReadString2 := (ReadString,ReadString); +function ReadlnString2 := ReadString2; + +function ReadInteger(prompt: string): integer; +begin + Result := PABCSystem.ReadInteger(prompt); + OutputList.RemoveAt(OutputList.Count-1); + OutputList.RemoveAt(OutputList.Count-1); +end; + +function ReadInteger2(prompt: string): (integer,integer); +begin + Result := PABCSystem.ReadInteger2(prompt); + OutputList.RemoveAt(OutputList.Count-1); + OutputList.RemoveAt(OutputList.Count-1); +end; + + +procedure Print(params args: array of object); +begin + foreach var ob in args do + begin + PABCSystem.Print(ob); + OutputList.RemoveAt(OutputList.Count-1) + end; +end; + +procedure Println(params args: array of object); +begin + Print(args); + Writeln; +end; + +procedure Print(ob: object); +begin + PABCSystem.Print(ob); + OutputList.RemoveAt(OutputList.Count-1) +end; + +procedure Print(s: string); +begin + PABCSystem.Print(s); + OutputList.RemoveAt(OutputList.Count-1) +end; + +type + IOLightSystem = class(__ReadSignalOISystem) + public + procedure write(obj: object); override; + begin + inherited write(obj); + OutputString += obj.ToString; + OutputList += obj; + end; + procedure writeln; override; + begin + inherited writeln; + OutputString += NewLine; + end; + procedure read(var x: integer); override; + begin + inherited Read(x); + InputList.Add(x); + end; + procedure read(var x: real); override; + begin + inherited Read(x); + InputList.Add(x); + end; + procedure read(var x: char); override; + begin + inherited Read(x); + InputList.Add(x); + end; + procedure read(var x: string); override; + begin + inherited Read(x); + InputList.Add(x); + end; + procedure read(var x: byte); override; + begin + inherited Read(x); + InputList.Add(x); + end; + procedure read(var x: shortint); override; + begin + inherited Read(x); + InputList.Add(x); + end; + procedure read(var x: smallint); override; + begin + inherited Read(x); + InputList.Add(x); + end; + procedure read(var x: word); override; + begin + inherited Read(x); + InputList.Add(x); + end; + procedure read(var x: longword); override; + begin + inherited Read(x); + InputList.Add(x); + end; + procedure read(var x: int64); override; + begin + inherited Read(x); + InputList.Add(x); + end; + procedure read(var x: uint64); override; + begin + inherited Read(x); + InputList.Add(x); + end; + procedure read(var x: single); override; + begin + inherited Read(x); + InputList.Add(x); + end; + procedure read(var x: boolean); override; + begin + inherited Read(x); + InputList.Add(x); + end; + procedure read(var x: BigInteger); override; + begin + inherited Read(x); + InputList.Add(x); + end; + end; + +function CompareElements(o1,o2: Object): boolean; +begin + if (o1 is real) and (o2 is real) then + begin + var r1 := real(o1); + var r2 := real(o2); + Result := Abs(r1-r2)<0.0001; + exit; + end; + Result := (o1.GetType = o2.GetType) and o1.Equals(o2); +end; + +function ToObjArray(a: array of integer) := a.Select(x->object(x)).ToArray; +function ToObjArray(a: array of real) := a.Select(x->object(x)).ToArray; +function ToObjArray(a: array of string) := a.Select(x->object(x)).ToArray; +function ToObjArray(a: array of char) := a.Select(x->object(x)).ToArray; +function ToObjArray(a: array of boolean) := a.Select(x->object(x)).ToArray; + +function CompareWithOutput(params a: array of object): TaskStatus; +begin + Result := NotCompleted; + if a.Length <> OutputList.Count then + exit; + Result := if a.Zip(OutputList,(x,y) -> CompareElements(x,y)).All(x->x) + then Completed + else NotCompleted; + {Result := Completed; + for var i:=0 to a.Length-1 do + if not CompareElements(a[i],OutputList[i]) then + begin + Result := NotCompleted; + exit; + end;} +end; + +function CompareSeqWithOutput(a: sequence of integer) := CompareWithOutput(ToObjArray(a.ToArray)); +function CompareSeqWithOutput(a: sequence of real) := CompareWithOutput(ToObjArray(a.ToArray)); +function CompareSeqWithOutput(a: sequence of string) := CompareWithOutput(ToObjArray(a.ToArray)); +function CompareSeqWithOutput(a: sequence of char) := CompareWithOutput(ToObjArray(a.ToArray)); +function CompareSeqWithOutput(a: sequence of boolean) := CompareWithOutput(ToObjArray(a.ToArray)); + +procedure ClearOutputListFromSpaces; +begin + OutputList := OutputList.Where(s -> (not (s is string)) or ((s as string) <> ' ')).ToList; +end; + +procedure FilterOnlyNumbers; +begin + OutputList := OutputList.Where(x -> (x is integer) or (x is real)).ToList; +end; + +var CheckTask: function(name: string): TaskStatus; + +procedure CheckMyPT; +begin + if CheckTask = nil then + exit; + try + var b := CheckTask(TaskName); + case b of + Completed: Writeln(#10'Задание выполнено'); + NotCompleted: Writeln(#10'Задание не выполнено'); + end; + except + on e: InputCount2Exception do + begin + if e.Count = 0 then + Writeln(#10+$'Требуется ввести по крайней мере {e.n} значения') + else Writeln(#10+$'Введено {e.Count} значения, а требуется ввести по крайней мере {e.n}'); + end; + on e: InputCountException do + begin + if e.Count = 0 then + Writeln(#10+$'Требуется ввести {e.n} значения') + else Writeln(#10+$'Введено {e.Count} значения, а требуется ввести {e.n}'); + end; + on e: InputTypeException do + begin + Writeln(#10+$'Неверно указан тип при вводе исходных данных'); + Writeln($'При вводе {e.n}-го элемента типа {e.ExpectedType} использована переменная типа {e.InputType}'); + end; + end; +end; + +initialization + CurrentIOSystem := new IOLightSystem; +finalization + CheckMyPT +end. \ No newline at end of file diff --git a/bin/Lib/Tasks.pas b/bin/Lib/Tasks.pas new file mode 100644 index 000000000..6f8ec5ec3 --- /dev/null +++ b/bin/Lib/Tasks.pas @@ -0,0 +1,15 @@ +// Базовый модуль-заглушка. Переопределяется в каталогах решаемых заданий +unit Tasks; + +uses LightPT; + +function CheckTaskT(name: string): TaskStatus; +begin + Result := AbsentTask; + WriteInfoToDatabase(name, result); +end; + +initialization + CheckTask := CheckTaskT; +finalization +end. \ No newline at end of file