Skip to content

Instantly share code, notes, and snippets.

@vazexqi
Created February 6, 2013 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save vazexqi/4726064 to your computer and use it in GitHub Desktop.
Save vazexqi/4726064 to your computer and use it in GitHub Desktop.
This file shows the types of checks that we perform and the types of error messages that we can report.
package edu.illinois.vlsicad.tests
import edu.illinois.vlsicad.core.FileFormatChecker
import edu.illinois.vlsicad.core.URPException
class FileFormatCheckerTest extends GroovyTestCase {
void testValidFile() {
// Should not have any exceptions thrown
FileFormatChecker checker = new FileFormatChecker(file: new File("test3.cubes"))
checker.checkFileFormat()
}
void testInvalidFirstLineFile() {
def msg = shouldFail(URPException) {
FileFormatChecker checker = new FileFormatChecker(file: new File("invalidFirstLine.cubes"))
checker.checkFileFormat()
}
assert 'Line #1 (i.e., expected number of variables) is not a number.' == msg
}
void testInvalidFirstLineFile_lessThan1() {
def msg = shouldFail(URPException) {
FileFormatChecker checker = new FileFormatChecker(file: new File("invalidFirstLineLessThan1.cubes"))
checker.checkFileFormat()
}
assert 'Line #1 (i.e., expected number of variables) needs to be > 0. Saw 0 instead.' == msg
}
void testInvalidSecondLine() {
def msg = shouldFail(URPException) {
FileFormatChecker checker = new FileFormatChecker(file: new File("invalidSecondLine.cubes"))
checker.checkFileFormat()
}
assert 'Line #2 (i.e., number of cubes) is not a number.' == msg
}
void testInvalidSecondLine_lessThan1() {
def msg = shouldFail(URPException) {
FileFormatChecker checker = new FileFormatChecker(file: new File("invalidSecondLineLessThan1.cubes"))
checker.checkFileFormat()
}
assert 'Line #2 (i.e., number of cubes) needs to be > 0. Saw 0 instead.' == msg
}
void testExtraWhiteSpaceLines() {
FileFormatChecker checker = new FileFormatChecker(file: new File("extraWhiteSpaceLines.cubes"))
checker.checkFileFormat()
}
void testExtraNonWhiteSpaceLines() {
def msg = shouldFail(URPException) {
FileFormatChecker checker = new FileFormatChecker(file: new File("extraNonWhitespaceLines.cubes"))
checker.checkFileFormat()
}
assert 'Some non-whitespace data still remain in the file after reading the list of cubes.' == msg
}
void testInvalidFirstCharOfCube() {
def msg = shouldFail(URPException) {
FileFormatChecker checker = new FileFormatChecker(file: new File("invalidFirstCharOfCube.cubes"))
checker.checkFileFormat()
}
assert 'First value of line #4 is not a number. Saw % but expected a number.' == msg
}
void testInvalidFirstCharOfCube_lessThan1() {
def msg = shouldFail(URPException) {
FileFormatChecker checker = new FileFormatChecker(file: new File("invalidFirstCharOfCubeLessThan1.cubes"))
checker.checkFileFormat()
}
assert 'Line #4 contains an invalid number of variables. Saw 0 but expected >= 0.' == msg
}
void testCubeContainsMoreVariables() {
def msg = shouldFail(URPException) {
FileFormatChecker checker = new FileFormatChecker(file: new File("cubeContainsMoreVariables.cubes"))
checker.checkFileFormat()
}
assert 'The line #4 contains more/less variables than expected. Saw 2 but expected 1.' == msg
}
void testCubeContainsLessVariables() {
def msg = shouldFail(URPException) {
FileFormatChecker checker = new FileFormatChecker(file: new File("cubeContainsLessVariables.cubes"))
checker.checkFileFormat()
}
assert 'The line #4 contains more/less variables than expected. Saw 2 but expected 3.' == msg
}
void testCubeContainsVariablesNotInRangeOver() {
def msg = shouldFail(URPException) {
FileFormatChecker checker = new FileFormatChecker(file: new File("cubeContainsVariablesNotInRangeOver.cubes"))
checker.checkFileFormat()
}
assert 'Line #4 contains some variables that are not within the range (1..2). Saw [3].' == msg
}
void testCubeContainsVariablesNotInRangeUnder() {
def msg = shouldFail(URPException) {
FileFormatChecker checker = new FileFormatChecker(file: new File("cubeContainsVariablesNotInRangeUnder.cubes"))
checker.checkFileFormat()
}
assert 'Line #4 contains some variables that are not within the range (1..2). Saw [0].' == msg
}
void testCubeContainsVariablesNotInRange() {
def msg = shouldFail(URPException) {
FileFormatChecker checker = new FileFormatChecker(file: new File("cubeContainsVariablesNotInRange.cubes"))
checker.checkFileFormat()
}
assert 'Line #4 contains some variables that are not within the range (1..2). Saw [3, 4].' == msg
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment