Exemplo n.º 1
0
Arquivo: tests.go Projeto: lanior/upc
func (self Problem) GenerateTestsInput() error {
	for i, test := range self.Tests {
		if input, ok := test.Input.(*GeneratedInput); ok {
			generator, ok := self.Generators[input.Generator]
			if !ok {
				return fmt.Errorf("Test #%d: unknown generator %s", i, input.Generator)
			}

			compiler := programs.GetCompiler(generator.Language)
			if compiler == nil {
				return fmt.Errorf("Test #%d: unknown generator compiler %s", i, generator.Language)
			}

			program := programs.Program{
				Name:       "generator",
				Arguments:  strings.Split(input.Parameters, " "),
				Compiler:   compiler,
				OutputFile: "input.txt",

				Files: programs.FileList{
					"generator": generator.SourceCode,
				},
			}

			result, err := program.Run()
			if err != nil {
				return fmt.Errorf("Test #%d: generator run failed: %s", i, err)
			}
			self.Tests[i].Input = ConstTestData(result)
		}
	}
	return nil
}
Exemplo n.º 2
0
Arquivo: tests.go Projeto: lanior/upc
func (self Problem) GenerateTestsOutput() error {
	for i, test := range self.Tests {
		if output, ok := test.Output.(*SolutionOutput); ok {
			solution, ok := self.Solutions[output.Solution]
			if !ok {
				return fmt.Errorf("Test #%d: unknown solution %s", i, output.Solution)
			}

			compiler := programs.GetCompiler(solution.Language)
			if compiler == nil {
				return fmt.Errorf("Test #%d: unknown solution compiler %s", i, solution.Language)
			}

			program := programs.Program{
				Name:       "solution",
				Compiler:   compiler,
				OutputFile: "output.txt",

				Files: programs.FileList{
					"solution":  solution.SourceCode,
					"input.txt": test.Input.Generate(),
				},
			}

			result, err := program.Run()
			if err != nil {
				return fmt.Errorf("Test #%d: solution run failed: %s", i, err)
			}
			self.Tests[i].Output = ConstSolutionData(result)
		}
	}
	return nil
}