Project

General

Profile

Tmp » History » Revision 2

Revision 1 (Николай Пакулин, 03/30/2015 05:49 PM) → Revision 2/6 (Николай Пакулин, 03/30/2015 05:56 PM)

h1. Кусочки кода 

 <pre> 
 static void assertTestString(CharSequence s) { 
		 int pos = 0; 
		 int len = s.length(); 
		 int rest = 0; 
		 char fill = 0; 
		
		 for (pos = 0; pos < len; pos++) { 
			 if (rest == 0) { 
				 fill = s.charAt(pos); 
				 if (fill == 0) { 
					 continue; 
				 } 
				 rest = fill - 1; 
				 continue; 
			 } else { 
				 assertEquals("Position " + pos + ": expected symbol \\u"  
						 + new Integer(fill) + " got \\u"  
						 + new Integer(s.charAt(pos)) 
					 , fill, s.charAt(pos)); 
				 rest --; 
			 } 
		 } 
		 assertEquals("expected "+ rest + " more characters",  
				 0, rest); 
	 } 
 </pre> 
         @Test 
	 public void testAssert() { 
		 assertTestString("\u0000"); 
		 assertTestString("\u0001"); 
		 assertTestString("\u0002\u0002\u0003\u0003\u0003"); 
	 } 
	
	 @Test 
	 public void testAssertFail() { 
		 String[] tests = new String[] { 
				 "\u0002", 
				 "\u0002\u0002\u0003" 
		 }; 
		 for (int i = 0; i < tests.length; i++) { 
			 try{ 
				 assertTestString(tests[i]); 
			 }catch (AssertionError e) { 
				 continue; 
			 } 
			 fail("Missed wrong string {" + tests[i] + "}"); 
		 } 
	 } 
 <pre> 

 </pre>