Project

General

Profile

Tmp » History » Revision 3

Revision 2 (Николай Пакулин, 03/30/2015 05:56 PM) → Revision 3/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> 
 <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>