--[[
---------------------------------------------------------------------------
Remote Train Control Program for Windows

© Copyright 2019 by Mark DiVecchio

	This file is part of Remote Train Control.

	Remote Train Control is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Remote Train Control is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Remote Train Control.  If not, see <http://www.gnu.org/licenses/>.

 Home Page : http://www.silogic.com/trains/RTC_Running.html
---------------------------------------------------------------------------]]
-- Semicolons are not required in Lua code
title = "Clock and Timing Test"
require("defines");

--[[---------------------------------------------------------------------------------------]]
function setup(Engine, TIU)
    x = os.clock();	-- Return CPU time since Lua started in seconds.
	clk = RunTime();
	print(string.format("(%.2f) : start time: %.4f seconds", clk, x));
	print(os.date("setup() %d %b %Y   %X"));
	return true;		-- false=setup failed, true=setup succeeded
	end
--[[---------------------------------------------------------------------------------------]]
function loop(Engine, TIU)
	print(string.format("(%.2f) : loop()", RunTime()));
	MyTIUNo = TIU;
	
    local s = 1.0;
	local i = 0.0;
	for i = 1,  100 do s = s * i end
	print("Product = " .. s);
	s = 0.0;
	local sprime = 0;
    for i = 1,  1000000000 do
		s = s + i
		sprime = sprime + i
		end
	print("Sum(number)  = " .. s);
	print("Sum(integer) = " .. sprime);
	local j = 10000000;
	while (j > 0) do
		j = j - 1;
		end
	local k =  100000000;
	repeat
		k = k - 1;
	until (k == 0);

	y = os.clock();
	clk2 = RunTime();
	print(string.format("(%.2f) : end time: %.4f seconds", clk2, y));
    print(string.format("(%.2f) : elapsed time: %.4f seconds", clk2 - clk, y - x));
	if (math.abs((y - x) - (clk2 - clk)) > 1.0) then
		print("Time is off by more than 1.0 seconds");
		else
		print("No errors");
		end;
	return Stop("DONE");
	end
--[[---------------------------------------------------------------------------------------]]
function cleanup()
	-- this function is called once when the user presses the [STOP] button
	print(os.date("cleanup()  %d %b %Y   %X"));
	return true;		-- false=cleanup failed, true=cleanup succeeded
	end
--[[---------------------------------------------------------------------------------------]]
function PlayBell(Eng, TIU)
	print("PlayBell(): Eng " .. Eng .. " TIU " .. TIU .. " Debug " .. Debug());
	-- ding dong
	return true;
end
Function01Name, Function01Label = PlayBell, "Sound Bell";

