#include "PreviewConfig.h"

#include <iostream>

namespace
{
int gFailures = 0;

void Expect(bool condition, const char* message)
{
	if (condition)
		return;

	std::cerr << "FAIL: " << message << "\n";
	++gFailures;
}

void TestTimerIntervalUsesConfiguredFps()
{
	Expect(RenderCadenceCompositor::PreviewTimerIntervalMilliseconds(25.0) == 40, "25 fps maps to 40 ms");
	Expect(RenderCadenceCompositor::PreviewTimerIntervalMilliseconds(50.0) == 20, "50 fps maps to 20 ms");
	Expect(RenderCadenceCompositor::PreviewTimerIntervalMilliseconds(59.94) == 16, "59.94 fps maps to 16 ms");
}

void TestInvalidFpsUsesDefault()
{
	Expect(
		RenderCadenceCompositor::PreviewTimerIntervalMilliseconds(0.0) ==
			RenderCadenceCompositor::PreviewTimerIntervalMilliseconds(RenderCadenceCompositor::kDefaultPreviewFps),
		"zero preview fps uses default interval");
	Expect(
		RenderCadenceCompositor::PreviewTimerIntervalMilliseconds(-10.0) ==
			RenderCadenceCompositor::PreviewTimerIntervalMilliseconds(RenderCadenceCompositor::kDefaultPreviewFps),
		"negative preview fps uses default interval");
}
}

int main()
{
	TestTimerIntervalUsesConfiguredFps();
	TestInvalidFpsUsesDefault();

	if (gFailures != 0)
	{
		std::cerr << gFailures << " preview config test failure(s).\n";
		return 1;
	}

	std::cout << "RenderCadenceCompositor preview config tests passed.\n";
	return 0;
}
