Advertisement
Guest User

TestCase.java

a guest
Nov 17th, 2013
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.43 KB | None | 0 0
  1. /**
  2.  * Verify correct operation of the StringShifter class.
  3.  *
  4.  * @file TestCase.java
  5.  * @author oz <oz@freqlabs.com>
  6.  * @date 2013-11-17
  7.  */
  8.  
  9. /*
  10. Copyright 2013 Freq Labs
  11.  
  12. Licensed under the Apache License, Version 2.0 (the "License");
  13. you may not use this file except in compliance with the License.
  14. You may obtain a copy of the License at
  15.  
  16.     http://www.apache.org/licenses/LICENSE-2.0
  17.  
  18. Unless required by applicable law or agreed to in writing, software
  19. distributed under the License is distributed on an "AS IS" BASIS,
  20. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. See the License for the specific language governing permissions and
  22. limitations under the License.
  23. */
  24.  
  25. public class TestCase
  26. {
  27.     public static void main(String[] args)
  28.     {
  29.         String cleartext = "ENCRYPTION";
  30.         String ciphertext = "QZODKBFUAZ";
  31.  
  32.         int encode_shift = 12;
  33.         int decode_shift = 26 - encode_shift;
  34.         int high_shift = 29;
  35.         int low_shift = -2;
  36.  
  37.         StringShifter shifter;
  38.         String output;
  39.         boolean result;
  40.  
  41.  
  42.         System.out.print("Testing encode: ");
  43.  
  44.         shifter = new StringShifter(cleartext);
  45.         output = shifter.shift(encode_shift);
  46.         result = output.equals(ciphertext);
  47.  
  48.         if (result == true)
  49.             System.out.println("PASS.");
  50.         else
  51.             System.out.printf("FAIL. Output: %s\n", output);
  52.  
  53.  
  54.         System.out.print("Testing decode: ");
  55.  
  56.         shifter = new StringShifter(ciphertext);
  57.         output = shifter.shift(decode_shift);
  58.         result = output.equals(cleartext);
  59.  
  60.         if (result == true)
  61.             System.out.println("PASS.");
  62.         else
  63.             System.out.printf("FAIL. Output: %s\n", output);
  64.  
  65.  
  66.         System.out.print("Testing high shift: ");
  67.  
  68.         shifter = new StringShifter(cleartext);
  69.         output = shifter.shift(high_shift);
  70.         result = output.equals(cleartext);
  71.  
  72.         if (result == true)
  73.             System.out.println("PASS.");
  74.         else
  75.             System.out.printf("FAIL. Output: %s\n", output);
  76.  
  77.  
  78.         System.out.print("Testing low shift: ");
  79.  
  80.         output = shifter.shift(low_shift);
  81.         result = output.equals(cleartext);
  82.  
  83.         if (result == true)
  84.             System.out.println("PASS.");
  85.         else
  86.             System.out.printf("FAIL. Output: %s\n", output);
  87.  
  88.  
  89.         System.out.println("Tests completed.");
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement