Ejemplo n.º 1
0
Archivo: tests.go Proyecto: 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
}
Ejemplo n.º 2
0
Archivo: tests.go Proyecto: 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
}
Ejemplo n.º 3
0
Archivo: helper.go Proyecto: lanior/upc
func (self ProblemHelper) GenerateSolution(solution *model.Solution, id int, pattern ...string) error {
	path, err := self.preparePath(pattern...)
	if err != nil {
		return err
	}

	compiler := programs.GetCompiler(solution.Language)
	if compiler == nil {
		return fmt.Errorf("Unknown solution language %s", solution.Language)
	}

	filename := strings.Replace(path, "{NAME}", utils.StripExt(solution.Name), -1)
	filename = strings.Replace(filename, "{EXT}", compiler.Extension, -1)
	filename = strings.Replace(filename, "{ID}", fmt.Sprintf("%d", id), -1)

	return self.Archive.WriteFile(filename, []byte(solution.SourceCode))
}