Test hashovací funkce + test češtiny v identifikátorech
authorFrantišek Kučera <franta-hg@frantovo.cz>
Tue May 25 13:54:21 2010 +0200 (2010-05-25)
changeset 1239135d52e8b0a
parent 122 f6c7168be1b7
child 124 e720890878ac
Test hashovací funkce + test češtiny v identifikátorech
Java Language Specification – 3.8 Identifiers:
http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#40625
java/nekurak.net-ejb/src/java/cz/frantovo/nekurak/ejb/PodnikEJB.java
java/nekurak.net-ejb/src/java/cz/frantovo/nekurak/ext/Texy.java
java/nekurak.net-lib/nbproject/project.properties
java/nekurak.net-lib/src/cz/frantovo/nekurak/util/Hash.java
java/nekurak.net-lib/test/cz/frantovo/nekurak/util/HashTest.java
     1.1 --- a/java/nekurak.net-ejb/src/java/cz/frantovo/nekurak/ejb/PodnikEJB.java	Mon May 24 20:25:55 2010 +0200
     1.2 +++ b/java/nekurak.net-ejb/src/java/cz/frantovo/nekurak/ejb/PodnikEJB.java	Tue May 25 13:54:21 2010 +0200
     1.3 @@ -48,7 +48,7 @@
     1.4  
     1.5      public int dopocitejSouradnice() {
     1.6  	/**
     1.7 -	 * TODO:    refaktorovat, změnit datové typy, souřadnice…
     1.8 +	 * TODO: refaktorovat, změnit datové typy, souřadnice…
     1.9  	 */
    1.10  	Geo g = new Geo();
    1.11  	int pocetAktualizovanych = 0;
     2.1 --- a/java/nekurak.net-ejb/src/java/cz/frantovo/nekurak/ext/Texy.java	Mon May 24 20:25:55 2010 +0200
     2.2 +++ b/java/nekurak.net-ejb/src/java/cz/frantovo/nekurak/ext/Texy.java	Tue May 25 13:54:21 2010 +0200
     2.3 @@ -41,9 +41,10 @@
     2.4  
     2.5  	    return vysledek.toString();
     2.6  	} catch (Exception e) {
     2.7 +	    // TODO: vyhazovat výjimku
     2.8  	    return "TODO:chyba";
     2.9  	} finally {
    2.10 -	    // TODO
    2.11 +	    // TODO: finally close();
    2.12  	}
    2.13      }
    2.14  }
     3.1 --- a/java/nekurak.net-lib/nbproject/project.properties	Mon May 24 20:25:55 2010 +0200
     3.2 +++ b/java/nekurak.net-lib/nbproject/project.properties	Tue May 25 13:54:21 2010 +0200
     3.3 @@ -31,7 +31,6 @@
     3.4  javac.test.classpath=\
     3.5      ${javac.classpath}:\
     3.6      ${build.classes.dir}:\
     3.7 -    ${libs.junit.classpath}:\
     3.8      ${libs.junit_4.classpath}
     3.9  javadoc.additionalparam=
    3.10  javadoc.author=false
     4.1 --- a/java/nekurak.net-lib/src/cz/frantovo/nekurak/util/Hash.java	Mon May 24 20:25:55 2010 +0200
     4.2 +++ b/java/nekurak.net-lib/src/cz/frantovo/nekurak/util/Hash.java	Tue May 25 13:54:21 2010 +0200
     4.3 @@ -35,6 +35,7 @@
     4.4       * @return hashovaný text v HEX tvaru
     4.5       * @throws NoSuchAlgorithmException neexistující hashovací algoritmus
     4.6       * @throws UnsupportedEncodingException nepodporované kódování znaků
     4.7 +     * @throws NullPointerException pokud je vstup null
     4.8       */
     4.9      public static String hashuj(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
    4.10  	MessageDigest md;
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/java/nekurak.net-lib/test/cz/frantovo/nekurak/util/HashTest.java	Tue May 25 13:54:21 2010 +0200
     5.3 @@ -0,0 +1,58 @@
     5.4 +package cz.frantovo.nekurak.util;
     5.5 +
     5.6 +import org.junit.Test;
     5.7 +import static org.junit.Assert.*;
     5.8 +
     5.9 +/**
    5.10 + * Kromě Hashe otestujeme i to, zda správně fungují i názvy metod napsané česky :-)
    5.11 + *
    5.12 + * <blockquote>
    5.13 + * „Letters and digits may be drawn from the entire Unicode character set,
    5.14 + * which supports most writing scripts in use in the world today,
    5.15 + * including the large sets for Chinese, Japanese, and Korean.
    5.16 + * This allows programmers to use identifiers in their programs that are written in their native languages.“
    5.17 + * </blockquote>
    5.18 + *
    5.19 + * @see <a href="http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#40625">Java Language Specification – 3.8 Identifiers</a>
    5.20 + * @author fiki
    5.21 + */
    5.22 +public class HashTest {
    5.23 +
    5.24 +    String 外滩 = "Bund";
    5.25 +    String 南京东路 = "Nanjing Road East";
    5.26 +
    5.27 +    @Test
    5.28 +    public void prázdnýŘetězec() throws Exception {
    5.29 +	testuj("", "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e");
    5.30 +    }
    5.31 +
    5.32 +    @Test
    5.33 +    public void prázdnýŘádek() throws Exception {
    5.34 +	testuj("\n", "be688838ca8686e5c90689bf2ab585cef1137c999b48c70b92f67a5c34dc15697b5d11c982ed6d71be1e1e7f7b4e0733884aa97c3f7a339a8ed03577cf74be09");
    5.35 +    }
    5.36 +
    5.37 +    @Test
    5.38 +    public void nullHodnota() throws Exception {
    5.39 +	try {
    5.40 +	    testuj(null, "Měla být vyhozena NullPointerException.");
    5.41 +	    fail();
    5.42 +	} catch (NullPointerException npe) {
    5.43 +	    // K chybě má dojít
    5.44 +	}
    5.45 +    }
    5.46 +
    5.47 +    @Test
    5.48 +    public void něco() throws Exception {
    5.49 +	testuj("Ahoj, jak to jde? :-)", "87e6e3c6487dc5ffee93d05cdc71a196f21181e357e61e1820d652ed9b601e179db92c1aaafc9cf57384498c1a52b89c82714dabdfd30b9eb8c7fd8d3fe53685");
    5.50 +    }
    5.51 +
    5.52 +    @Test
    5.53 +    public void čeština() throws Exception {
    5.54 +	testuj("čeština a další unicode – → | @{#@$%${*&…˙×ׄ东方明珠塔“‚&‘‚“‚", "f9750a7f3fa04356510285af61bbdd40b108e04c2abad69130c5929561fa2765e263707147f779ac5f4be348005ce0fc810334822ba0a50f1d5c41719413277e");
    5.55 +    }
    5.56 +
    5.57 +    private void testuj(String vstup, String pozadovanyVystup) throws Exception {
    5.58 +	String vystup = Hash.hashuj(vstup);
    5.59 +	assertEquals(pozadovanyVystup, vystup);
    5.60 +    }
    5.61 +}