In: Computer Science
How can we write an application that calculates connascence of an application?
Solution:-
Connascence is a process where we check th strength of two different parts of the application. Connascence may sound like waste of space and time in the application during application testing, but it playes an important role to prioritise what should be refactored first.
Connascence can be done for algorithms, block of code or coupling in the application. Connascence of algorithm is where multiple block of code must agree on a particular algorithm for giving ouput.
Connascence of code is where two piece of code agrees on certain point of calculation for it to work further. Connascence of code is same for block of code here all it does is refactorize the parts on the priority bases during the unit testing.
How it is done:-
Lets consider two piece of code, consider an example of connascence of algorithm.
def write_data_to_file(data_string): with open('/path/to/file', 'wb') as file_values: file.write(data_string.encode('utf8'))
def read_data_from_file(): with open('/path/to/file', 'rb') as file_values: return file.read().decode('utf8')
The test code for these two block would be:-
We are testing for the users password.
def test_user_password(self): user = User.new(name="xyz") actual = user.password() expected = hashlib.md5(user.name).hexdigest() self.assertEqual(expected, actual)