From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1657 invoked by alias); 1 Sep 2008 22:23:15 -0000 Received: (qmail 1622 invoked by uid 22791); 1 Sep 2008 22:23:09 -0000 X-Spam-Check-By: sourceware.org Received: from smtp813.mail.ird.yahoo.com (HELO smtp813.mail.ird.yahoo.com) (217.146.188.73) by sourceware.org (qpsmtpd/0.31) with SMTP; Mon, 01 Sep 2008 22:21:58 +0000 Received: (qmail 9426 invoked from network); 1 Sep 2008 22:21:54 -0000 Received: from unknown (HELO orthanc.middle-earth.co.uk) (hughes2002@btinternet.com@86.149.18.213 with plain) by smtp813.mail.ird.yahoo.com with SMTP; 1 Sep 2008 22:21:51 -0000 X-YMail-OSG: j5YvRh0VM1lvW31kindWl4jbuCL6KqFR.SFd5TMZPm_KJWkb6tlyWVpeU7HoQ2unJqyNFiIHx4y_jPbePvtuyU_SMqbdVcJfnh0GDOHcHP156kHNinDolWXFbjmEZtQaKndPWdYW05KuWcAGxMOXllbC X-Yahoo-Newman-Property: ymail-3 Received: from rivendell.middle-earth.co.uk ([192.168.0.1]) by orthanc.middle-earth.co.uk with smtp (Exim 4.63) (envelope-from ) id 1KaHmQ-0008V1-DH for mauve-patches@sources.redhat.com; Mon, 01 Sep 2008 23:21:50 +0100 Received: by rivendell.middle-earth.co.uk (sSMTP sendmail emulation); Mon, 1 Sep 2008 23:21:50 +0100 Date: Mon, 01 Sep 2008 22:23:00 -0000 From: Andrew John Hughes To: mauve-patches@sources.redhat.com Subject: FYI: Tests for java.util.Scanner Message-ID: <20080901222150.GA20647@rivendell.middle-earth.co.uk> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="r5Pyd7+fXNt84Ff3" Content-Disposition: inline User-Agent: Mutt/1.5.16 (2007-06-09) X-IsSubscribed: yes Mailing-List: contact mauve-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: mauve-patches-owner@sourceware.org X-SW-Source: 2008/txt/msg00061.txt.bz2 --r5Pyd7+fXNt84Ff3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 2350 This patch adds the tests submitted by Laszlo with his Scanner implementation to Mauve. All now pass with IcedTea6. ChangeLog: 2008-09-01 Andrew John Hughes * gnu/testlet/java/util/Scanner/Base.java, * gnu/testlet/java/util/Scanner/BigDecimalInteger.java, * gnu/testlet/java/util/Scanner/Booleans.java, * gnu/testlet/java/util/Scanner/DoubleFloat.java, * gnu/testlet/java/util/Scanner/FileInput.java, * gnu/testlet/java/util/Scanner/FindPattern.java, * gnu/testlet/java/util/Scanner/FindWithinHorizon.java, * gnu/testlet/java/util/Scanner/FishString.java, * gnu/testlet/java/util/Scanner/Inputs.java, * gnu/testlet/java/util/Scanner/LotsOfInts.java, * gnu/testlet/java/util/Scanner/LotsOfPMInts.java, * gnu/testlet/java/util/Scanner/LotsOfPMLong.java, * gnu/testlet/java/util/Scanner/LotsOfPMShort.java, * gnu/testlet/java/util/Scanner/MultiLine.java: Added headers, replaced MyScanner with Scanner, fixed location of temporary files, general formatting and naming cleanup. * gnu/testlet/java/util/Scanner/Radix.java, * gnu/testlet/java/util/Scanner/SkipPattern.java: Likewise, and converted to use harness.check instead of harness.fail. 2007-07-25 Laszlo Andras Hernadi * gnu/testlet/java/util/Scanner/Base.java, * gnu/testlet/java/util/Scanner/BigDecimalInteger.java, * gnu/testlet/java/util/Scanner/Booleans.java, * gnu/testlet/java/util/Scanner/DoubleFloat.java, * gnu/testlet/java/util/Scanner/FileInput.java, * gnu/testlet/java/util/Scanner/FindPattern.java, * gnu/testlet/java/util/Scanner/FindWithinHorizon.java, * gnu/testlet/java/util/Scanner/FishString.java, * gnu/testlet/java/util/Scanner/Inputs.java, * gnu/testlet/java/util/Scanner/LotsOfInts.java, * gnu/testlet/java/util/Scanner/LotsOfPMInts.java, * gnu/testlet/java/util/Scanner/LotsOfPMLong.java, * gnu/testlet/java/util/Scanner/LotsOfPMShort.java, * gnu/testlet/java/util/Scanner/MultiLine.java, * gnu/testlet/java/util/Scanner/Radix.java, * gnu/testlet/java/util/Scanner/SkipPattern.java: New tests for java.util.Scanner. -- Andrew :) Support Free Java! Contribute to GNU Classpath and the OpenJDK http://www.gnu.org/software/classpath http://openjdk.java.net PGP Key: 94EFD9D8 (http://subkeys.pgp.net) Fingerprint = F8EF F1EA 401E 2E60 15FA 7927 142C 2591 94EF D9D8 --r5Pyd7+fXNt84Ff3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="scanner.diff" Content-length: 49255 Index: gnu/testlet/java/util/Scanner/Base.java =================================================================== RCS file: gnu/testlet/java/util/Scanner/Base.java diff -N gnu/testlet/java/util/Scanner/Base.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/Scanner/Base.java 1 Sep 2008 22:16:11 -0000 @@ -0,0 +1,81 @@ +// Copyright (c) 2007 Hernadi Laszlo + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +// Tags: not-a-test + +package gnu.testlet.java.util.Scanner; + +import gnu.testlet.TestHarness; +import gnu.testlet.Testlet; + +import java.io.File; + +/** + * @author E0327023 Hernadi Laszlo @ 14.02.2007 - 12:13:06 + */ +public abstract class Base implements Testlet +{ + protected TestHarness myHarness = null; + + protected final boolean doCleanUP = false; + + protected String fileName = null; + + protected File aktFile; + + protected boolean isEnabled = true; + protected boolean forceAll = true; + + public void test (final TestHarness harness) + { + if (!isEnabled && !forceAll) + { + System.out.println ("\t\tTest Disabled..."); + return; + } + + this.myHarness = harness; + if (this.fileName != null) + { + this.aktFile = new File (myHarness.getTempDirectory() + + myHarness.getSeparator() + + this.fileName); + myHarness.debug("Using file: " + aktFile.toString()); + if (this.doCleanUP) + { + this.aktFile.deleteOnExit (); + } + } + try + { + doTest (); + } + catch (Throwable e) + { + e.printStackTrace (); + } + } + + protected void setDefaultFilename () + { + this.fileName = this.getClass ().getName () + ".txt"; + } + + protected abstract void doTest (); +} Index: gnu/testlet/java/util/Scanner/BigDecimalInteger.java =================================================================== RCS file: gnu/testlet/java/util/Scanner/BigDecimalInteger.java diff -N gnu/testlet/java/util/Scanner/BigDecimalInteger.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/Scanner/BigDecimalInteger.java 1 Sep 2008 22:16:11 -0000 @@ -0,0 +1,150 @@ +// Copyright (c) 2007 Hernadi Laszlo + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +// Tags: JDK1.5 +/** + * + */ +package gnu.testlet.java.util.Scanner; + +import java.math.BigDecimal; +import java.math.BigInteger; + +import java.util.Random; +import java.util.Scanner; + +/** + * @author E0327023 Hernadi Laszlo + * @ 15.02.2007 - 13:37:48 + * + */ +public class BigDecimalInteger extends Base +{ + + /** + * The amount of BigDecimals and BigIntegers to generate and test + */ + private final static int AMOUNT = 5000; + + public BigDecimalInteger () + { + this.isEnabled = false; + } + + /* (non-Javadoc) + * @see gnu.testlet.java.util.Scanner.TestBase#doTest() + */ + @Override protected void doTest () + { + BigDecimal[]decimals = new BigDecimal[AMOUNT]; + BigInteger[]integers = new BigInteger[decimals.length]; + long runID = System.currentTimeMillis (); + Random rand = new Random (runID); + StringBuilder sBuff = new StringBuilder (1000); + String inStr; + int i; + BigDecimal tmpDec; + BigInteger tmpInt; + boolean fund; + boolean failed; + int runsLeft = 10; + + for (i = 0; i < decimals.length; i++) + { + decimals[i] = new BigDecimal (rand.nextDouble () - 0.5); + integers[i] = BigInteger.valueOf (rand.nextInt ()); +// if (i % 100 == 0) +// System.out.println(i); + } + + sBuff.append (decimals[0] + " " + integers[0]); + for (i = 1; i < decimals.length; i++) + { + sBuff.append (" " + decimals[i] + " " + integers[i]); +// if (i % 100 == 0) +// System.out.println(i); + } + + inStr = sBuff.toString (); +// Scanner s = new Scanner (inStr); + Scanner s = new Scanner (inStr); + //s.setUseLocale (false); +// System.out.println(inStr); + +// System.out.println("len : " + inStr.length()); + + i = 0; + while (s.hasNext () && runsLeft > 0) + { + fund = false; + failed = false; + if (s.hasNextBigDecimal ()) + { + tmpDec = s.nextBigDecimal (); + if (!tmpDec.equals (decimals[i])) + { + failed = true; + this.myHarness.fail ("#" + i + + " : bad result by nextBigDeciaml() : (" + + tmpDec + " != " + decimals[i] + + ") possibly needed : \"" + s.next () + + "\""); + } + fund = true; + } + else + { + this.myHarness.fail ("no BigDecimal found..."); + } + if (s.hasNextBigInteger ()) + { + tmpInt = s.nextBigInteger (); + if (!tmpInt.equals (integers[i])) + { + failed = true; + this.myHarness.fail ("#" + i + + " : bad result by nextBigInteger() : " + + tmpInt + " != " + integers[i]); + } + fund = true; + } + else + { + this.myHarness.fail ("no BigInteger found..."); + } + +// if (i % 100 == 0) +// System.out.println(i); + if (!fund) + { + this.myHarness.fail ("\"" + s.next () + + "\" is neighter BigDecimal nor BigInteger"); + } + i++; + if (failed) + { + runsLeft--; + } + } + this.myHarness.check (i, decimals.length, + "not all read (" + i + " / " + decimals.length + + ")"); + } + +} Index: gnu/testlet/java/util/Scanner/Booleans.java =================================================================== RCS file: gnu/testlet/java/util/Scanner/Booleans.java diff -N gnu/testlet/java/util/Scanner/Booleans.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/Scanner/Booleans.java 1 Sep 2008 22:16:11 -0000 @@ -0,0 +1,83 @@ +// Copyright (c) 2007 Hernadi Laszlo + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +// Tags: JDK1.5 +// Tags: JDK1.5 +/** + * + */ +package gnu.testlet.java.util.Scanner; + +import java.util.Random; +import java.util.Scanner; + +/** + * @author E0327023 Hernadi Laszlo + * @ 15.02.2007 - 13:10:31 + * + */ +public class Booleans extends Base +{ + /** + * The amount of booleans to generate and test. + */ + private final static int AMOUNT = 100; + + + /* (non-Javadoc) + * @see gnu.testlet.java.util.Scanner.TestBase#doTest() + */ + @Override protected void doTest () + { + boolean[]values = new boolean[AMOUNT]; + boolean hasNext; + boolean aktValue; + String inStr; + int i; + Random rand = new Random (System.currentTimeMillis ()); + + for (i = 0; i < values.length; i++) + { + values[i] = rand.nextBoolean (); + } + inStr = "" + values[0]; + + for (i = 1; i < values.length; i++) + { + inStr += " " + values[i]; + } + + Scanner s = new Scanner (inStr); + i = 0; + hasNext = s.hasNextBoolean (); + while (hasNext) + { + aktValue = s.nextBoolean (); + this.myHarness.check (aktValue, values[i], + "nextBoolean() is wrong : " + aktValue + + " != " + values[i]); + i++; + hasNext = s.hasNextBoolean (); + } + this.myHarness.check (i, values.length, + "not all values (" + i + " / " + values.length + + ")"); + } + +} Index: gnu/testlet/java/util/Scanner/DoubleFloat.java =================================================================== RCS file: gnu/testlet/java/util/Scanner/DoubleFloat.java diff -N gnu/testlet/java/util/Scanner/DoubleFloat.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/Scanner/DoubleFloat.java 1 Sep 2008 22:16:11 -0000 @@ -0,0 +1,117 @@ +// Copyright (c) 2007 Hernadi Laszlo + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +// Tags: JDK1.5 +/** + * + */ +package gnu.testlet.java.util.Scanner; + +import java.util.Random; +import java.util.Scanner; + +/** + * @author E0327023 Hernadi Laszlo + * @ 15.02.2007 - 21:06:41 + * + */ +public class DoubleFloat extends Base +{ + /** + * The amount of doubles and floats to generate and test. + */ + private final static int AMOUNT = 10000; + + + public DoubleFloat () + { + this.isEnabled = false; + } + + /* (non-Javadoc) + * @see gnu.testlet.java.util.Scanner.TestBase#doTest() + */ + @Override protected void doTest () + { + double[] doubleZ = new double[AMOUNT]; + float[] floatZ = new float[doubleZ.length]; + long runID = System.currentTimeMillis (); + Random rand = new Random (runID); + int i; + StringBuffer tmpStr = new StringBuffer (1000); + String inStr; + + double aktDouble; + float aktFloat; + + for (i = 0; i < doubleZ.length; i++) + { + doubleZ[i] = rand.nextDouble () - 0.5d; + floatZ[i] = rand.nextFloat () - 0.5f; + } + + tmpStr.append (doubleZ[0] + " " + floatZ[0]); + for (i = 1; i < doubleZ.length; i++) + { + tmpStr.append (" " + doubleZ[i] + " " + floatZ[i]); + } + + inStr = tmpStr.toString (); + Scanner s = new Scanner (inStr); + //s.setUseLocale (false); +// Scanner s = new Scanner(inStr); + + i = 0; + while (s.hasNext () && i < doubleZ.length) + { + if (s.hasNextDouble ()) + { + aktDouble = s.nextDouble (); + this.myHarness.check (aktDouble, doubleZ[i], + "#" + i + " : bad nextDouble() (" + + aktDouble + " != " + doubleZ[i]); + } + else + { + this.myHarness.fail ("#" + i + " : not double... (" + s.next () + + ")"); + } + if (s.hasNextFloat ()) + { + aktFloat = s.nextFloat (); + this.myHarness.check (aktFloat, floatZ[i], + "#" + i + " : bad nextFloat() (" + + aktFloat + " != " + floatZ[i]); + } + else + { + this.myHarness.fail ("#" + i + " : not float... (" + s.next () + + ")"); + } + i++; + } + + if (i != doubleZ.length) + { + this.myHarness.fail ("not all (" + i + " / " + doubleZ.length); + } + + } + +} Index: gnu/testlet/java/util/Scanner/FileInput.java =================================================================== RCS file: gnu/testlet/java/util/Scanner/FileInput.java diff -N gnu/testlet/java/util/Scanner/FileInput.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/Scanner/FileInput.java 1 Sep 2008 22:16:11 -0000 @@ -0,0 +1,100 @@ +// Copyright (c) 2007 Hernadi Laszlo + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +// Tags: JDK1.5 + +/** + * + */ +package gnu.testlet.java.util.Scanner; + +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; + +import java.util.Scanner; + +/** + * @author E0327023 Hernadi Laszlo + * @ 14.02.2007 - 12:20:18 + * + */ +public class FileInput extends Base +{ + public FileInput () + { + setDefaultFilename (); + } + + /* (non-Javadoc) + * @see gnu.testlet.java.util.Scanner.TestBase#doTest() + */ + @Override protected void doTest () + { + this.myHarness.checkPoint ("File Input"); + + String[]testWords = + { + "This", "is", "a", "simple", "Test", "don't", "panik", "it's", "just", + "a", "Teset"}; + testWords[0] = testWords[0].trim (); + String testString = testWords[0]; + String tmpStr; + int i; + + for (i = 1; i < testWords.length; i++) + { + testWords[i] = testWords[i].trim (); + testString += " " + testWords[i].trim (); + } + + try + { + FileOutputStream fos = new FileOutputStream (this.aktFile); + fos.write (testString.getBytes ()); + fos.flush (); + fos.close (); + Scanner s = new Scanner (aktFile); + i = 0; + while (s.hasNext ()) + { + tmpStr = s.next (); + this.myHarness.check (tmpStr, testWords[i], + "next() -> \"" + tmpStr + "\" != \"" + + testWords[i] + "\""); + // System.out.println("\"" + tmpStr + "\" ?= \"" + testWords[i] + "\""); + i++; + } + this.myHarness.check (i, testWords.length, + "Incomplete read... (" + i + " / " + + testWords.length + ")"); + s.close (); + } + catch (FileNotFoundException e) + { + this.myHarness.fail ("Could not create file"); + } + catch (IOException e) + { + this.myHarness.fail ("Could not write to File \"" + + this.aktFile.getName () + "\""); + } + } + +} Index: gnu/testlet/java/util/Scanner/FindPattern.java =================================================================== RCS file: gnu/testlet/java/util/Scanner/FindPattern.java diff -N gnu/testlet/java/util/Scanner/FindPattern.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/Scanner/FindPattern.java 1 Sep 2008 22:16:11 -0000 @@ -0,0 +1,70 @@ +// Copyright (c) 2007 Hernadi Laszlo + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +// Tags: JDK1.5 + +/** + * + */ +package gnu.testlet.java.util.Scanner; + +import java.util.Scanner; + +/** + * @author E0327023 Hernadi Laszlo + * @ 19.02.2007 - 03:16:19 + * + */ +public class FindPattern extends Base +{ + + private static final String FISH_STR = "1 fish 2 fish red fish blue fish "; //$NON-NLS-1$ + + /* (non-Javadoc) + * @see gnu.testlet.java.util.Scanner.TestBase#doTest() + */ + @Override protected void doTest () + { + Scanner s3 = new Scanner (FISH_STR); + String pattern1 = "\\d+"; // "(\\d+) fish "; + String pattern2 = "\\w+"; // "(\\w+) fish "; + String[] patterns = + { null, pattern1, pattern1, pattern2, pattern2}; + String[]values = + { null, "1", "2", "red", "blue"}; // the null is required... + String tmpStr; + boolean rc; + int i; + + i = 1; + s3.useDelimiter (" fish "); + do + { + rc = s3.hasNext (patterns[i]); + myHarness.check(rc, "Next item doesn't match " + patterns[i]); + if (!rc) myHarness.fail("Stopping early; encountered \"" + s3.next() + "\""); + tmpStr = s3.next (patterns[i]); + myHarness.check(tmpStr, values[i], "wrong result : \"" + tmpStr + "\" != \"" + + values[i] + "\""); + i++; + } + while (rc && i < patterns.length); + } + +} Index: gnu/testlet/java/util/Scanner/FindWithinHorizon.java =================================================================== RCS file: gnu/testlet/java/util/Scanner/FindWithinHorizon.java diff -N gnu/testlet/java/util/Scanner/FindWithinHorizon.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/Scanner/FindWithinHorizon.java 1 Sep 2008 22:16:11 -0000 @@ -0,0 +1,59 @@ +// Copyright (c) 2007 Hernadi Laszlo + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +// Tags: JDK1.5 +/** + * + */ +package gnu.testlet.java.util.Scanner; + +import java.util.Scanner; + +/** + * @author E0327023 Hernadi Laszlo + * @ 24.02.2007 - 20:10:24 + * + */ +public class FindWithinHorizon extends Base +{ + + /* (non-Javadoc) + * @see gnu.testlet.java.util.Scanner.TestBase#doTest() + */ + @Override protected void doTest () + { + String fishString = "1 fish 2 fish red fish blue fish"; + Scanner s = new Scanner (fishString); + String tmpStr = ""; + int i; + + for (i = 0; i < fishString.length (); i++) + { + // from : http://www.cs.princeton.edu/introcs/15inout/In.java.html + // (?s) for DOTALL mode so . matches any character, including a line termination character + // 1 says look only one character ahead + // consider precompiling the pattern + tmpStr += s.findWithinHorizon ("(?s).", 1); + } + myHarness.check (tmpStr.equals(fishString), "\"" + tmpStr + "\" == \"" + fishString + "\""); + if (s.hasNext ()) + myHarness.fail ("should not has next..."); + } + +} Index: gnu/testlet/java/util/Scanner/FishString.java =================================================================== RCS file: gnu/testlet/java/util/Scanner/FishString.java diff -N gnu/testlet/java/util/Scanner/FishString.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/Scanner/FishString.java 1 Sep 2008 22:16:11 -0000 @@ -0,0 +1,89 @@ +// Copyright (c) 2007 Hernadi Laszlo + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +// Tags: JDK1.5 + +/** + * + */ +package gnu.testlet.java.util.Scanner; + +import gnu.testlet.Testlet; + +import java.util.Scanner; + +import java.util.regex.MatchResult; + +/** + * @author E0327023 Hernadi Laszlo @ 12.02.2007 - 23:00:30 + */ +public class FishString extends Base +{ + + @Override protected void doTest () + { + String input = "1 fish 2 fish red fish blue fish"; + String delimiter = "\\s*fish\\s*"; + String tmpStr; + String[] values = + { + null, "1", "2", "red", "blue"}; // the null is required... + int i; + + this.myHarness.checkPoint ("Fisch String [" + input + "]"); + Scanner s1 = new Scanner (input); + s1.useDelimiter (delimiter); + tmpStr = s1.delimiter ().pattern (); + this.myHarness.check (tmpStr, delimiter, + "get / setDelimiter fail (\"" + tmpStr + + "\" != \"" + delimiter); + this.myHarness.check (s1.hasNext (), true, "first hasNext()"); + this.myHarness.check (s1.hasNextInt (), true, "first hasNextInt()"); + this.myHarness.check (s1.nextInt (), 1, "nextInt()"); + this.myHarness.check (s1.hasNextInt (), true, "hasNextInt()"); + this.myHarness.check (s1.hasNextBoolean (), false, "hasNextBoolean()"); + this.myHarness.check (s1.hasNextByte (), true, "hasNextByte()"); + this.myHarness.check (s1.nextInt (), 2, "2. nextInt()"); + this.myHarness.check (s1.hasNext (), true, "3. hasNext()"); + this.myHarness.check (s1.hasNextBigInteger (), false, + "hasNextBigInteger()"); + this.myHarness.check (s1.next (), "red", "3. next()"); + this.myHarness.check (s1.next (), "blue", "4. next()"); + this.myHarness.check (s1.hasNext (), false, "letztes hasNext()"); + s1.close (); + + // Scanner s2 = new Scanner(input); + Scanner s2 = new Scanner (input); + s2.findInLine ("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)"); + MatchResult mResult = s2.match (); + for (i = 1; i <= mResult.groupCount (); i++) + { + this.myHarness.check (mResult.group (i), values[i], + "wrong result : \"" + mResult.group (i) + + "\" != \"" + values[i] + "\""); + // System.out.println(mResult.group(i)); + } + if (i != values.length) + { + this.myHarness.fail ("not all results... (" + i + " != " + + (values.length) + ")"); + } + s2.close (); + } +} Index: gnu/testlet/java/util/Scanner/Inputs.java =================================================================== RCS file: gnu/testlet/java/util/Scanner/Inputs.java diff -N gnu/testlet/java/util/Scanner/Inputs.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/Scanner/Inputs.java 1 Sep 2008 22:16:11 -0000 @@ -0,0 +1,227 @@ +// Copyright (c) 2007 Hernadi Laszlo + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +// Tags: JDK1.5 +/** + * + */ +package gnu.testlet.java.util.Scanner; + +import java.io.ByteArrayInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; + +import java.util.Random; +import java.util.Scanner; + +/** + * @author E0327023 Hernadi Laszlo + * @ 26.02.2007 - 04:15:47 + * + */ +public class Inputs extends Base +{ + /** + * The amount of long numbers to generate and test. + */ + private final static int AMOUNT = 20000; + + public Inputs () + { + fileName = getClass().getName () + ".txt"; + this.isEnabled = false; + } + + /* (non-Javadoc) + * @see gnu.testlet.java.util.Scanner.TestBase#doTest() + */ + @Override protected void doTest () + { + long[] numbers = new long[AMOUNT]; + Random r = new Random (System.currentTimeMillis ()); + int i; + long tmp; + int errors; + final long max = 20000000000000L, mean = max >> 1; + StringBuffer tmpBuff = new StringBuffer (10000); + FileOutputStream fos = null; + Scanner s = null; + + String[]charSets = {"windows-1252"}; + String aktName; + + int aktCS; + + for (i = 0; i < numbers.length; i++) + { + tmp = ((long) (r.nextFloat () * max) - mean); + numbers[i] = tmp; + } + tmpBuff.insert (0, "" + numbers[0]); + + for (i = 1; i < numbers.length; i++) + { + tmpBuff.append (" " + numbers[i]); + } + + try + { + fos = new FileOutputStream (this.aktFile); + fos.write (tmpBuff.toString ().getBytes ()); + fos.flush (); + fos.close (); + +// Scanner s = new Scanner (aktFile); + + myHarness.debug ("Testing Readable input..."); + errors = 0; + s = new Scanner (new FileReader (this.aktFile)); + i = 0; + while (s.hasNextLong ()) + { + tmp = s.nextLong (); + if (tmp != numbers[i]) + { + errors++; + this.myHarness.fail ("Readable : nextLong() -> " + tmp + + " != " + numbers[i]); + } + i++; + } + if (errors == 0) + myHarness.debug ("all OK"); + else + this.myHarness.fail (errors + " errors.."); + + myHarness.debug ("Testing ReadableByteChanel input..."); + errors = 0; + s = new Scanner ((new FileInputStream (this.aktFile)).getChannel ()); + i = 0; + while (s.hasNextLong ()) + { + tmp = s.nextLong (); + if (tmp != numbers[i]) + { + errors++; + this.myHarness.fail ("ReadableByteChanel : nextLong() -> " + + tmp + " != " + numbers[i]); + } + i++; + } + if (errors == 0) + myHarness.debug ("all OK"); + else + this.myHarness.fail (errors + " errors.."); + + for (aktCS = 0; aktCS < charSets.length; aktCS++) + { + aktName = "Testing File + CharSet \"" + charSets[aktCS] + "\""; + myHarness.debug (aktName); + errors = 0; + s = new Scanner (this.aktFile, charSets[aktCS]); + i = 0; + while (s.hasNextLong ()) + { + tmp = s.nextLong (); + if (tmp != numbers[i]) + { + errors++; + this.myHarness.fail (aktName + " : nextLong() -> " + tmp + + " != " + numbers[i]); + } + i++; + } + if (errors == 0) + myHarness.debug ("all OK"); + else + this.myHarness.fail (errors + " errors.."); + + aktName = + "Testing InputStream + CharSet \"" + charSets[aktCS] + "\""; + myHarness.debug (aktName); + errors = 0; + s = + new Scanner (new + ByteArrayInputStream (tmpBuff.toString (). + getBytes ()), + charSets[aktCS]); + i = 0; + while (s.hasNextLong ()) + { + tmp = s.nextLong (); + if (tmp != numbers[i]) + { + errors++; + this.myHarness.fail (aktName + " : nextLong() -> " + tmp + + " != " + numbers[i]); + } + i++; + } + if (errors == 0) + myHarness.debug ("all OK"); + else + this.myHarness.fail (errors + " errors.."); + + aktName = + "Testing ReadableByteChanel + CharSet \"" + charSets[aktCS] + + "\""; + myHarness.debug (aktName); + errors = 0; + s = + new Scanner ((new FileInputStream (this.aktFile)).getChannel (), + charSets[aktCS]); + i = 0; + while (s.hasNextLong ()) + { + tmp = s.nextLong (); + if (tmp != numbers[i]) + { + errors++; + this.myHarness.fail (aktName + " : nextLong() -> " + tmp + + " != " + numbers[i]); + } + i++; + } + if (errors == 0) + myHarness.debug ("all OK"); + else + this.myHarness.fail (errors + " errors.."); + + } + + this.myHarness.check (i, numbers.length, + "Incomplete read... (" + i + " / " + + numbers.length + ")"); + s.close (); + } + catch (FileNotFoundException e) + { + this.myHarness.fail ("Could not create file"); + } + catch (IOException e) + { + this.myHarness.fail ("Could not write to File \"" + + this.aktFile.getName () + "\""); + } + } + +} Index: gnu/testlet/java/util/Scanner/LotsOfInts.java =================================================================== RCS file: gnu/testlet/java/util/Scanner/LotsOfInts.java diff -N gnu/testlet/java/util/Scanner/LotsOfInts.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/Scanner/LotsOfInts.java 1 Sep 2008 22:16:12 -0000 @@ -0,0 +1,96 @@ +// Copyright (c) 2007 Hernadi Laszlo + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +// Tags: JDK1.5 +// Tags: JDK1.5 + +package gnu.testlet.java.util.Scanner; + +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; + +import java.util.Random; +import java.util.Scanner; + +public class LotsOfInts extends Base +{ + public LotsOfInts () + { + this.isEnabled = false; + this.fileName = this.getClass ().getName () + ".txt"; + } + + @Override protected void doTest () + { + this.myHarness.checkPoint ("Reading lots of positive ints"); + + int[] numbers = new int[100000]; + Random r = new Random (System.currentTimeMillis ()); + int i; + int tmp; + final int max = 1000000; + StringBuilder tmpBuff = new StringBuilder (10000); + FileOutputStream fos = null; + + for (i = 0; i < numbers.length; i++) + { + tmp = (int) (r.nextFloat () * max); + numbers[i] = tmp; + } + tmpBuff.insert (0, "" + numbers[0]); + + for (i = 1; i < numbers.length; i++) + { + tmpBuff.append (" " + numbers[i]); + } + + try + { + fos = new FileOutputStream (this.aktFile); + fos.write (tmpBuff.toString ().getBytes ()); + fos.flush (); + fos.close (); + + Scanner s = new Scanner (this.aktFile); + i = 0; + while (s.hasNextInt ()) + { + tmp = s.nextInt (); + this.myHarness.check (tmp, numbers[i], + "nextInt() -> " + tmp + " != " + numbers[i]); + i++; + } + this.myHarness.check (i, numbers.length, + "Incomplete read... (" + i + " / " + + numbers.length + ")"); + s.close (); + } + catch (FileNotFoundException e) + { + this.myHarness.fail ("Could not create file"); + } + catch (IOException e) + { + this.myHarness.fail ("Could not write to File \"" + + this.aktFile.getName () + "\""); + } + } + +} Index: gnu/testlet/java/util/Scanner/LotsOfPMInts.java =================================================================== RCS file: gnu/testlet/java/util/Scanner/LotsOfPMInts.java diff -N gnu/testlet/java/util/Scanner/LotsOfPMInts.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/Scanner/LotsOfPMInts.java 1 Sep 2008 22:16:12 -0000 @@ -0,0 +1,98 @@ +// Copyright (c) 2007 Hernadi Laszlo + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +// Tags: JDK1.5 + +package gnu.testlet.java.util.Scanner; + +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; + +import java.util.Random; +import java.util.Scanner; + +public class LotsOfPMInts extends Base +{ + public LotsOfPMInts () + { + this.isEnabled = false; + setDefaultFilename (); + } + + @Override protected void doTest () + { + this.myHarness.checkPoint ("Reading lots of positive ints"); + + int[] numbers = new int[100000]; + long runID = System.currentTimeMillis (); + Random rand = new Random (runID); + int i; + int tmp; + final int max = 1000000, mean = max >> 1; + StringBuilder tmpBuff = new StringBuilder (10000); + FileOutputStream fos = null; + + myHarness.debug ("runID : " + runID); + + for (i = 0; i < numbers.length; i++) + { + tmp = (int) (rand.nextFloat () * max) - mean; + numbers[i] = tmp; + } + tmpBuff.insert (0, "" + numbers[0]); + + for (i = 1; i < numbers.length; i++) + { + tmpBuff.append (" " + numbers[i]); + } + + try + { + fos = new FileOutputStream (this.aktFile); + fos.write (tmpBuff.toString ().getBytes ()); + fos.flush (); + fos.close (); + + Scanner s = new Scanner (aktFile); + i = 0; + while (s.hasNextInt ()) + { + tmp = s.nextInt (); + this.myHarness.check (tmp, numbers[i], + "nextInt() -> " + tmp + " != " + numbers[i]); + i++; + } + this.myHarness.check (i, numbers.length, + "Incomplete read... (" + i + " / " + + numbers.length + ")"); + s.close (); + } + catch (FileNotFoundException e) + { + this.myHarness.fail ("Could not create file"); + } + catch (IOException e) + { + this.myHarness.fail ("Could not write to File \"" + + this.aktFile.getName () + "\""); + } + } + +} Index: gnu/testlet/java/util/Scanner/LotsOfPMLong.java =================================================================== RCS file: gnu/testlet/java/util/Scanner/LotsOfPMLong.java diff -N gnu/testlet/java/util/Scanner/LotsOfPMLong.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/Scanner/LotsOfPMLong.java 1 Sep 2008 22:16:12 -0000 @@ -0,0 +1,97 @@ +// Copyright (c) 2007 Hernadi Laszlo + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +// Tags: JDK1.5 + +package gnu.testlet.java.util.Scanner; + +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; + +import java.util.Random; +import java.util.Scanner; + +public class LotsOfPMLong extends Base +{ + public LotsOfPMLong () + { + this.fileName = this.getClass ().getName () + ".txt"; + } + + @Override protected void doTest () + { + this.myHarness.checkPoint ("Reading lots of shorts"); + + long[] numbers = new long[20000]; + long runID = System.currentTimeMillis (); + Random rand = new Random (runID); + int i; + long tmp; + final long max = 20000000000000L, mean = max >> 1; + StringBuilder tmpBuff = new StringBuilder (10000); + FileOutputStream fos = null; + + myHarness.debug ("runID : " + runID); + + for (i = 0; i < numbers.length; i++) + { + tmp = ((long) (rand.nextFloat () * max) - mean); + numbers[i] = tmp; + } + tmpBuff.insert (0, "" + numbers[0]); + + for (i = 1; i < numbers.length; i++) + { + tmpBuff.append (" " + numbers[i]); + } + + try + { + fos = new FileOutputStream (this.aktFile); + fos.write (tmpBuff.toString ().getBytes ()); + fos.flush (); + fos.close (); + + Scanner s = new Scanner (aktFile); + i = 0; + while (s.hasNextLong ()) + { + tmp = s.nextLong (); + this.myHarness.check (tmp, numbers[i], + "nextLong() -> " + tmp + " != " + numbers[i]); + i++; + } + this.myHarness.check (i, numbers.length, + "Incomplete read... (" + i + " / " + + numbers.length + ")"); + s.close (); + } + catch (FileNotFoundException e) + { + this.myHarness.fail ("Could not create file"); + } + catch (IOException e) + { + this.myHarness.fail ("Could not write to File \"" + + this.aktFile.getName () + "\""); + } + } + +} Index: gnu/testlet/java/util/Scanner/LotsOfPMShort.java =================================================================== RCS file: gnu/testlet/java/util/Scanner/LotsOfPMShort.java diff -N gnu/testlet/java/util/Scanner/LotsOfPMShort.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/Scanner/LotsOfPMShort.java 1 Sep 2008 22:16:12 -0000 @@ -0,0 +1,99 @@ +// Copyright (c) 2007 Hernadi Laszlo + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +// Tags: JDK1.5 + +package gnu.testlet.java.util.Scanner; + +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; + +import java.util.Random; +import java.util.Scanner; + +public class LotsOfPMShort extends Base +{ + public LotsOfPMShort () + { + this.isEnabled = false; + this.fileName = this.getClass ().getName () + ".txt"; + } + + @Override protected void doTest () + { + this.myHarness.checkPoint ("Reading lots of shorts"); + + short[] numbers = new short[10000]; + long runID = System.currentTimeMillis (); + Random rand = new Random (runID); + int i; + short tmp; + final short max = 20000, mean = max >> 1; + StringBuilder tmpBuff = new StringBuilder (10000); + FileOutputStream fos = null; + + myHarness.debug ("runID : " + runID); + + for (i = 0; i < numbers.length; i++) + { + tmp = (short) ((short) (rand.nextFloat () * max) - mean); + numbers[i] = tmp; + } + tmpBuff.insert (0, "" + numbers[0]); + + for (i = 1; i < numbers.length; i++) + { + tmpBuff.append (" " + numbers[i]); + } + + try + { + fos = new FileOutputStream (this.aktFile); + fos.write (tmpBuff.toString ().getBytes ()); + fos.flush (); + fos.close (); + + Scanner s = new Scanner (aktFile); + i = 0; + while (s.hasNextShort ()) + { + tmp = s.nextShort (); + this.myHarness.check (tmp, numbers[i], + "nextShort() -> " + tmp + " != " + + numbers[i]); + i++; + } + this.myHarness.check (i, numbers.length, + "Incomplete read... (" + i + " / " + + numbers.length + ")"); + s.close (); + } + catch (FileNotFoundException e) + { + this.myHarness.fail ("Could not create file"); + } + catch (IOException e) + { + this.myHarness.fail ("Could not write to File \"" + + this.aktFile.getName () + "\""); + } + } + +} Index: gnu/testlet/java/util/Scanner/MultiLine.java =================================================================== RCS file: gnu/testlet/java/util/Scanner/MultiLine.java diff -N gnu/testlet/java/util/Scanner/MultiLine.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/Scanner/MultiLine.java 1 Sep 2008 22:16:12 -0000 @@ -0,0 +1,74 @@ +// Copyright (c) 2007 Hernadi Laszlo + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +// Tags: JDK1.5 + +/** + * + */ +package gnu.testlet.java.util.Scanner; + +import java.io.ByteArrayInputStream; + +import java.util.Scanner; + +/** + * @author E0327023 Hernadi Laszlo + * @ 14.02.2007 - 12:17:51 + * + */ +public class MultiLine extends Base +{ + + /* (non-Javadoc) + * @see gnu.testlet.java.util.Scanner.TestBase#doTest() + */ + @Override protected void doTest () + { + this.myHarness.checkPoint ("Multi line read - linewise"); + + String[] lines = + { + "1. Line: aaa bbb ccc", "2. line: aaa bbb aaa", "3. line: bbb aaa"}; + String newLine = System.getProperty ("line.separator"); + int i; + String tmp = lines[0]; + String result; + byte[]buffer; + + for (i = 1; i < lines.length; i++) + { + tmp += newLine + lines[i]; + } + tmp += newLine; + buffer = tmp.getBytes (); + ByteArrayInputStream inStr = new ByteArrayInputStream (buffer); + + Scanner s = new Scanner (inStr); + for (i = 0; i < lines.length; i++) + { + this.myHarness.check (s.hasNextLine (), true, + (i + 1) + ". hasNextLine()"); + result = s.nextLine (); + this.myHarness.check (result, lines[i], + (i + 1) + ". nextLine() [" + result + "]"); + } + } + +} Index: gnu/testlet/java/util/Scanner/Radix.java =================================================================== RCS file: gnu/testlet/java/util/Scanner/Radix.java diff -N gnu/testlet/java/util/Scanner/Radix.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/Scanner/Radix.java 1 Sep 2008 22:16:12 -0000 @@ -0,0 +1,75 @@ +// Copyright (c) 2007 Hernadi Laszlo + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +// Tags: JDK1.5 +/** + * + */ +package gnu.testlet.java.util.Scanner; + +import java.math.BigInteger; + +import java.util.Scanner; + +/** + * @author E0327023 Hernadi Laszlo + * @ 26.02.2007 - 05:28:44 + * + */ +public class Radix extends Base +{ + + /* (non-Javadoc) + * @see gnu.testlet.java.util.Scanner.TestBase#doTest() + */ + @Override protected void doTest () + { + String testStr = "5F 7FFF 4F3F3F6F 3F3F2EF3FFEE 4FFAAEEFFAA"; + Scanner s = new Scanner (testStr); + + myHarness.check(s.hasNextByte (16), "hasNextByte(16)"); + myHarness.check(s.nextByte(16), 95, "nextByte is 95"); + myHarness.check(s.hasNextShort(16), "hasNextShort(16)"); + myHarness.check(s.nextShort(16), 32767, "nextShort is 32767"); + myHarness.check(s.hasNextInt(16), "hasNextInt(16)"); + myHarness.check(s.nextInt(16), 1329545071, "nextInt is 1329545071"); + myHarness.check(s.hasNextLong(16), "hasNextLong(16)"); + myHarness.check(s.nextLong(16), 69540603232238L, "nextLong is 69540603232238"); + myHarness.check(s.hasNextBigInteger(16), "hasNextBigInteger(16)"); + myHarness.check(s.nextBigInteger(16), BigInteger.valueOf(5496130961322L), + "nextBigInteger is 5496130961322"); + + s = new Scanner (testStr).useRadix (16); + myHarness.check(s.radix(), 16, "radix was not set to 16"); + + myHarness.check(s.hasNextByte (), "hasNextByte()"); + myHarness.check(s.nextByte(), 95, "nextByte is 95"); + myHarness.check(s.hasNextShort(), "hasNextShort()"); + myHarness.check(s.nextShort(), 32767, "nextShort is 32767"); + myHarness.check(s.hasNextInt(), "hasNextInt()"); + myHarness.check(s.nextInt(), 1329545071, "nextInt is 1329545071"); + myHarness.check(s.hasNextLong(), "hasNextLong()"); + myHarness.check(s.nextLong(), 69540603232238L, "nextLong is 69540603232238"); + myHarness.check(s.hasNextBigInteger(), "hasNextBigInteger()"); + myHarness.check(s.nextBigInteger(), BigInteger.valueOf(5496130961322L), + "nextBigInteger is 5496130961322"); + + } + +} Index: gnu/testlet/java/util/Scanner/SkipPattern.java =================================================================== RCS file: gnu/testlet/java/util/Scanner/SkipPattern.java diff -N gnu/testlet/java/util/Scanner/SkipPattern.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/Scanner/SkipPattern.java 1 Sep 2008 22:16:12 -0000 @@ -0,0 +1,55 @@ +// Copyright (c) 2007 Hernadi Laszlo + +// This file is part of Mauve. + +// Mauve is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2, or (at your option) +// any later version. + +// Mauve is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Mauve; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +// Tags: JDK1.5 + +package gnu.testlet.java.util.Scanner; + +import java.util.Scanner; + +/** + * @author E0327023 Hernadi Laszlo + * @ 19.02.2007 - 03:16:19 + * + */ +public class SkipPattern extends Base +{ + + private static final String FISH_STR = "1 fish 2 fish red fish blue fish "; //$NON-NLS-1$ + + /* (non-Javadoc) + * @see gnu.testlet.java.util.Scanner.TestBase#doTest() + */ + @Override protected void doTest () + { + Scanner s = new Scanner(FISH_STR); + String[] values = { "1", "2", "red", "blue"}; + int i; + String tmpStr; + + for (i = 0; i < values.length; i++) + { + tmpStr = s.next (); + myHarness.check(tmpStr.equals (values[i]), tmpStr + " = " + values[i]); + s = s.skip (" ").skip ("fish"); + } + + } + +} --r5Pyd7+fXNt84Ff3--