Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better parsing #25

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
expected 'line length to be 3, got 4' at 1:0
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
3 3 300
.#$.
#..
.$.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
expected 'eol' at 1:2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 5 1
.$$..
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
expected 'eol' at 3:1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
3 3 300
.#$
#..
.$.
Empty file.
51 changes: 27 additions & 24 deletions Busquedas/Derrame de Petroleo/tests/test-validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,44 @@
import sys
import re
import unittest
import parsy as p

from omegaup.validator import validatortest
import omegaup.validator.parsing as oup


class Test(unittest.TestCase):
@p.generate
def inputParser():
R = yield oup.boundedInteger(1, 2000, 'R')
yield oup.space
C = yield oup.boundedInteger(1, 2000, 'C')
yield oup.space
K = yield oup.boundedInteger(1, 10**7, 'K')
yield oup.eol

def test(self):
with open('data.in', 'r') as handle:
lines = handle.read().split('\n')
def evalLineLength(line):
if len(line) != C:
return f'line length {C}, got {len(line)}'
return None

self.assertEqual(lines[-1], '', "file doesn't end with EOL")
lines.pop()
lineWithoutDollar = oup.label('line w/o $', p.regex(r'[.#]*') << oup.eol)
lineWithDollar = oup.label('line', p.regex(r'[.#]*\$?[.#]*') << oup.eol)

first_line_reg = re.compile(r'^(\d+) (\d+) (\d+)$')
self.assertTrue(first_line_reg.match(lines[0]),
"first line incorrectly formatted")
R, C, K = map(int, lines[0].split(' '))
saw_dollar = False
for r in range(R):
parser = lineWithoutDollar if saw_dollar else lineWithDollar
line = yield oup.guard(parser, evalLineLength)
saw_dollar |= '$' in line

# Validar R, C, K
self.assertTrue(1 <= R <= 2000, "R out of bounds")
self.assertTrue(1 <= C <= 2000, "C out of bounds")
self.assertTrue(0 <= K <= 10**7, "K out of bounds")
if not saw_dollar:
return p.fail('$ to be present in map')

# Validar número de lineas
self.assertEqual(len(lines), 1 + R, "line count mismatch")

saw_dollar = False
map_reg = re.compile(r'^[.#$]+$')
for line in lines[1:]:
self.assertTrue(map_reg.match(line), "invalid character in map")
self.assertEqual(len(line), C, "line width mismatch")
if '$' in line:
self.assertFalse(saw_dollar, "too many $ in map")
class Test(unittest.TestCase):

self.assertFalse(saw_dollar, "no $ in map")
def test(self):
with open('data.in', 'r') as handle:
inputParser.parse(handle.read())


if __name__ == '__main__':
Expand Down
2 changes: 2 additions & 0 deletions Programacion Basica/A+B/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/*.out
!tests/invalid-cases/*.out
1 change: 0 additions & 1 deletion Programacion Basica/A+B/cases/0.out

This file was deleted.

2 changes: 1 addition & 1 deletion Programacion Basica/A+B/cases/1.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1 1
23 45
1 change: 0 additions & 1 deletion Programacion Basica/A+B/cases/1.out

This file was deleted.

1 change: 0 additions & 1 deletion Programacion Basica/A+B/cases/10.out

This file was deleted.

1 change: 0 additions & 1 deletion Programacion Basica/A+B/cases/2.out

This file was deleted.

1 change: 0 additions & 1 deletion Programacion Basica/A+B/cases/3.out

This file was deleted.

1 change: 0 additions & 1 deletion Programacion Basica/A+B/cases/4.out

This file was deleted.

1 change: 0 additions & 1 deletion Programacion Basica/A+B/cases/5.out

This file was deleted.

1 change: 0 additions & 1 deletion Programacion Basica/A+B/cases/6.out

This file was deleted.

1 change: 0 additions & 1 deletion Programacion Basica/A+B/cases/7.out

This file was deleted.

1 change: 0 additions & 1 deletion Programacion Basica/A+B/cases/8.out

This file was deleted.

1 change: 0 additions & 1 deletion Programacion Basica/A+B/cases/9.out

This file was deleted.

28 changes: 0 additions & 28 deletions Programacion Basica/A+B/config.yaml

This file was deleted.

1 change: 1 addition & 0 deletions Programacion Basica/A+B/examples/sample.in
1 change: 1 addition & 0 deletions Programacion Basica/A+B/examples/sample1.in
28 changes: 28 additions & 0 deletions Programacion Basica/A+B/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"title": "A + B",
"source": "Curso OMI (Orac)",

"limits": {
"TimeLimit": 1000,
"MemoryLimit": 134217728,
"InputLimit": 134217728,
"OutputLimit": 134217728,
"ExtraWallTime": 3000,
"OverallWallTimeLimit": 60000
},

"validator": {
"name": "token-caseless",
"limits": {
"TimeLimit": 1000
}
},

"misc": {
"alias": "COMI-a-b",
"visibility": 1,
"languages": "all",
"email_clarifications": 0,
"admin-groups": ["workshop-2017"]
}
}
10 changes: 5 additions & 5 deletions Programacion Basica/A+B/statements/es.markdown
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Deberás escribir un programa que tome dos números y los sume.

#Entrada
# Entrada

La entrada consiste en dos enteros, $a$ y $b$, separados por un espacio en blanco.

#Salida
# Salida

Tu salida debe ser un solo número entero, la suma de $a$ y $b$.
Tu salida debe ser un solo número entero, la suma de $a$ y $b$.

#Ejemplo
# Ejemplo
||input
5 5
||output
Expand All @@ -23,6 +23,6 @@ Tu salida debe ser un solo número entero, la suma de $a$ y $b$.
23 + 45 = 68
||end

#Límites
# Límites

* $a$ y $b$ pueden ser enteros desde $1$ hasta $1,000$
11 changes: 11 additions & 0 deletions Programacion Basica/A+B/testplan
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
0 9
1 9
2 9
3 9
4 9
5 9
6 9
7 9
8 9
9 9
10 10
1 change: 1 addition & 0 deletions Programacion Basica/A+B/tests/data.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4 2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
expected 'eol' at 0:3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4 5.3
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
expected 'integer between 1 and 1000'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4 0
Empty file.
33 changes: 33 additions & 0 deletions Programacion Basica/A+B/tests/test-validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# no-self-use
# pylint: disable=R0201

import sys
import re
import unittest
import parsy as p

from omegaup.validator import validatortest
import omegaup.validator.parsing as oup


@p.generate
def inputParser():
a = yield oup.boundedInteger(1, 1000, 'a')
yield oup.space
b = yield oup.boundedInteger(1, 1000, 'b')
yield oup.eol
return (a, b)


class Test(unittest.TestCase):

def test(self):
with open('data.in', 'r') as handle:
(a, b) = inputParser.parse(handle.read())


if __name__ == '__main__':
validatortest.main()
16 changes: 16 additions & 0 deletions Programacion Basica/A+B/tests/tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"solutions": [
{
"filename": "../solutions/solution.cpp",
"verdict": "AC"
},
{
"filename": "../solutions/solution2.cpp",
"verdict": "AC"
}
],
"inputs": {
"filename": "test-validator.py"
},
"max_score": 100
}
3 changes: 3 additions & 0 deletions problems.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
},
{
"path": "Programacion Basica/Palindromos"
},
{
"path": "Programacion Basica/A+B"
}
]
}