#!/usr/bin/env python # -*- coding: utf-8 -*- # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # @file: hw/chkpath/code/python/run.py # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # This file is released under BSD 2-clause license. from pyhost.scorer import CodeStyleScorer, CoverageScorer import SafeRunner if (__name__ == '__main__'): scorers = [ (CodeStyleScorer.FromHandinDir(ignore_files=['run.py','succ.py','BinNode.py']), 0.1), # Note that the CoverageScorer takes 1.0 as total weight, but # uses stmt_weight=0.4, branch_weight=0.5 to control the score (CoverageScorer.FromHandinDir( files_to_cover=['succ.py'], stmt_weight=0.6, branch_weight=0.3, ), 1.0), ] SafeRunner.run(scorers)
@maker.class_('illegal triangle b >= a + c') def illegal_triangle_2(obj): return (obj.a < obj.b + obj.c) and (not(obj.b < obj.a + obj.c)) @maker.class_('illegal triangle c >= a + b') def illegal_triangle_3(obj): return (obj.a < obj.b + obj.c) and (obj.b < obj.a + obj.c) and (not(obj.c < obj.a + obj.b)) @maker.class_('regular triangle') def regular_triangle(obj): return (obj.a < obj.b + obj.c) and (obj.b < obj.a + obj.c) and(obj.c < obj.a + obj.b) and (obj.a == obj.b) and (obj.a == obj.c) and (obj.b == obj.c) @maker.class_('isosceles triangle a == b') def isosceles_triangle_1(obj): return (obj.a < obj.b + obj.c) and (obj.b < obj.a + obj.c) and(obj.c < obj.a + obj.b) and (obj.a == obj.b) and (not(obj.a == obj.c)) and (not(obj.b == obj.c)) @maker.class_('isosceles triangle a == c') def isosceles_triangle_2(obj): return (obj.a < obj.b + obj.c) and (obj.b < obj.a + obj.c) and(obj.c < obj.a + obj.b) and (not(obj.a == obj.b)) and (obj.a == obj.c) and (not(obj.b == obj.c)) @maker.class_('isosceles triangle b == c') def isosceles_triangle_3(obj): return (obj.a < obj.b + obj.c) and (obj.b < obj.a + obj.c) and(obj.c < obj.a + obj.b) and (not(obj.a == obj.b)) and (not(obj.a == obj.c)) and (obj.b == obj.c) @maker.class_('normal triangle') def normal_triangle(obj): return (obj.a < obj.b + obj.c) and (obj.b < obj.a + obj.c) and(obj.c < obj.a + obj.b) and (not(obj.a == obj.b)) and (not(obj.a == obj.c)) and (not(obj.b == obj.c)) # Run this scorer SafeRunner.run(maker.get_scorers(weight=1.0))
return (obj.a > 0 and obj.b > 0 and obj.c > 0) and \ (obj.a + obj.c == obj.b) @maker.boundary('zero data (one of a, b, c == 0)') def zero_data_1(obj): return (obj.a == 0 and obj.b != 0 and obj.c != 0) or \ (obj.a != 0 and obj.b == 0 and obj.c != 0) or \ (obj.a != 0 and obj.b != 0 and obj.c == 0) @maker.boundary('zero data (all of a, b, c == 0)') def zero_data_2(obj): return (obj.a == 0 and obj.b == 0 and obj.c == 0) @maker.class_('negative data (one of a, b, c < 0)') def negative_data_1(obj): return (obj.a < 0 and obj.b >= 0 and obj.c >= 0) or \ (obj.a >= 0 and obj.b < 0 and obj.c >= 0) or \ (obj.a >= 0 and obj.b >= 0 and obj.c < 0) @maker.class_('negative data (all of a, b, c < 0)') def negative_data_2(obj): return (obj.a < 0 and obj.b < 0 and obj.c < 0) # Run this scorer SafeRunner.run(maker.get_scorers(weight=1.0))
def test_emptyPath(self): self.assertEqual(self._reform_path(''), '') self.assertEqual(self._reform_path('/'), '/') self.assertEqual(self._reform_path('.'), '') self.assertEqual(self._reform_path('/.'), '/') self.assertEqual(self._reform_path('1/..'), '') self.assertEqual(self._reform_path('1/../'), '') self.assertEqual(self._reform_path('/1/..'), '/') self.assertEqual(self._reform_path('/1/../'), '/') def test_tailSlash(self): self.assertEqual(self._reform_path('\\1\\2\\'), '/1/2') self.assertEqual(self._reform_path('//1//2//'), '/1/2') self.assertEqual(self._reform_path('1/./2/./'), '1/2') self.assertEqual(self._reform_path('/1/./2/./'), '/1/2') self.assertEqual(self._reform_path('1/2/3/../4/../../'), '1') self.assertEqual(self._reform_path('/1/2/3/../4/../../'), '/1') self.assertRaises(ValueError, self._reform_path, '../') self.assertRaises(ValueError, self._reform_path, '/../') self.assertRaises(ValueError, self._reform_path, '1/../../') self.assertRaises(ValueError, self._reform_path, '/1/../../') if (__name__ == '__main__'): scorers = [ (CodeStyleScorer.FromHandinDir(ignore_files=['run.py']), 0.1), (UnitTestScorer.FromTestCase(ReformPathTestCase), 0.9), ] SafeRunner.run(scorers)