Thread: Need help correcting a test

  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,574

    Need help correcting a test

    Finally got back to programming the alu during my week off and tried to fix varying bugs, this bug however eludes me, basically I converted a couple of bit search functions to accept searching for first/final 0 instead of first/final 1 but later found it was giving erroneous result/s which leads to the failure of a previously working alup_mov_int2flt() function (at least on positive numbers, recently found out I had made some misunderstanding somewhere about how negative numbers are stored in floats and that lead to erroneous results regarding normal +-*/ math). I've now added a couple of tests for those functions having realised there was none already added to the tests that were being done and tried running them only to find they were not catching the error of the known faulty function (alup_first_bit_with_val). Can someone take a look and see if they can correct the test for me (haven't uploaded any changes yet because I did a massive overhaul and didn't want to upload broken code, if you need to see it say so and I will upload a zip of the project and just link to that instead). Btw the bug was incorrect position & bit being given back (was one off), I'll circle back to that bug after the test for it is corrected.

    Code:
    START_TEST( test_alup_first_bit_with_val )
    {
    	if ( !stop_checks )
    	{
    		uintmax_t before = 0x86 << _i, expect = 0x2 << _i;
    		alup_t _BEFORE;
    		alub_t result;
    		
    		alup_init_unsigned( _BEFORE, &before, bitsof(uint_t) );
    		
    		result = alup_first_bit_with_val( &_BEFORE, true );
    		
    		stop_checks = ((*(result.ptr) & result.mask) != expect);
    		ck_assert_msg
    		(
    			(*(result.ptr) & result.mask) == expect
    			, "Expected 0x%016jX, Got 0x%016jX, Before = 0x%016jX"
    			, expect
    			, result.mask
    			, before
    		);
    		
    		expect = _i + 1;
    		stop_checks = (stop_checks || result.pos != expect);
    		ck_assert_msg
    		(
    			result.pos == expect
    			, "Expected %ju, Got %zu"
    			, expect
    			, result.pos
    		);
    		
    		
    		stop_checks = (stop_checks || result.bit != expect);
    		ck_assert_msg
    		(
    			result.bit == expect
    			, "Expected %ju, Got %zu"
    			, expect
    			, result.bit
    		);
    	}
    }
    END_TEST
    
    START_TEST( test_alup_final_bit_with_val )
    {
    	if ( !stop_checks )
    	{
    		uintmax_t before = 0x86 << _i, expect = 0x80 << _i;
    		alup_t _BEFORE;
    		alub_t result;
    		
    		alup_init_unsigned( _BEFORE, &before, bitsof(uint_t) );
    		
    		result = alup_final_bit_with_val( &_BEFORE, true );
    		
    		stop_checks = ((*(result.ptr) & result.mask) != expect);
    		ck_assert_msg
    		(
    			(*(result.ptr) & result.mask) == expect
    			, "Expected 0x%016jX, Got 0x%016jX, Before = 0x%016jX"
    			, expect
    			, result.mask
    			, before
    		);
    		
    		expect = _i + 7;
    		stop_checks = (stop_checks || result.pos != expect);
    		ck_assert_msg
    		(
    			result.pos == expect
    			, "Expected %ju, Got %zu"
    			, expect
    			, result.pos
    		);
    		
    		
    		stop_checks = (stop_checks || result.bit != expect);
    		ck_assert_msg
    		(
    			result.bit == expect
    			, "Expected %ju, Got %zu"
    			, expect
    			, result.bit
    		);
    	}
    }
    END_TEST
    Edit: Went ahead and compressed the project anyways, alu.tar.gz - Google Drive

  2. #2
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,574
    Was not able to correct the tests but did fix the problem functions:
    Code:
    alub_t alup_first_bit_with_val( alup_t const * const _SRC, bool val )
    {
    	alub_t s = {0};
    	
    	if ( _SRC && _SRC->data )
    	{
    		/* Ensure is only 1 or 0 contained if maps to integer */
    		val = !!val;
    		
    		s = alup_first_bit( _SRC );
    			
    		while ( s.bit < _SRC->last )
    		{
    			if ( !!( *(s.ptr) & s.mask ) == val )
    				break;
    			
    			alub_inc(&s);
    		}
    	}
    	
    	return s;
    }
    
    alub_t alup_final_bit_with_val( alup_t const * const _SRC, bool val )
    {
    	alub_t s = {0};
    	
    	if ( _SRC && _SRC->data )
    	{
    		/* Ensure is only 1 or 0 contained if maps to integer */
    		val = !!val;
    		
    		s = alup_final_bit( _SRC );
    			
    		while ( s.bit > _SRC->from )
    		{
    			if ( !!( *(s.ptr) & s.mask ) == val )
    				break;
    			
    			alub_dec(&s);
    		}
    	}
    	
    	return s;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can somebody help me correcting this code.
    By Michael Kwan in forum C Programming
    Replies: 1
    Last Post: 04-05-2015, 11:51 AM
  2. Can Someone please help me with correcting my code???
    By John120788 in forum C Programming
    Replies: 13
    Last Post: 06-07-2013, 04:18 AM
  3. Reading and correcting.
    By Remm in forum C Programming
    Replies: 3
    Last Post: 02-27-2008, 04:13 PM
  4. Correcting a file?
    By Kings in forum C++ Programming
    Replies: 3
    Last Post: 03-14-2003, 04:18 PM
  5. correcting my last thread...
    By demonus in forum C Programming
    Replies: 3
    Last Post: 11-04-2002, 12:48 PM

Tags for this Thread