New answers tagged

3

Ah, a fine Spec. Has been a while since I've used Hspec, but your tests seem reasonable. So, first of all: well done! There is one bit we should fix though, and you have identified it yourself: the property tests. QuickCheck's newtypes Creating any kind of number and then checking whether it's positive is a hassle, as half the numbers will get discarded per ...


2

Not familiar with CAN yet so just one suggestion: Get rid of those print statements, use the logging module instead. See also here: Basic Logging Tutorial and here: Logging Cookbook Some benefits: being able to write to multiple destinations: console + text files in different formats if desired increase or reduce verbosity at will keep a permanent record of ...


3

In-band error signalling return signal_data # ... # reports false if message fails to be received return False is problematic. You're forcing the caller of this code to understand that the return value has at least two different types: boolean or whatever "signal data" is. The Python way to approach this is to use exceptions. Rather than (say) re-...


2

Protected Variables Underscore is used to mark a variable protected in python classes _counter = 0 should be counter = 0 Use of min_<foo<max_ is permitted in python if (ct > ct_min) and (ct < ct_max): can be if ct_min < ct < ct_max:


3

Pick your framework You're learning new stuff, so your style will develop as you progress. While the code is still fresh, try to refactor as you go, so that the code moves towards a consistent style. If you want to move towards FluentAssertions, then try to use it for all of your assertions. Rather than this: // Fluent Assertions accountExpected.Should()....


2

You've got some answers to your initial questions, which you seem to be happy with, so I'm not going to address them. There are some things that I noticed about your code, however which I think are worth mentioning. Tests Naming Consider losing 'test' from the front of your test names. All the methods are annotated and in test class. Having the word test ...


4

This is a decent improvement over your first posting. Let's start off with some things you are doing right. Your use of Decimal is correct. Many first attempts will incorrectly use double. Nice indentation. Most names are fairly good. Whereas many will over-abbreviate, you tend to make the names too long. Let's think of how an ATM should work. A ...


1

Three observations: There are two many assert statements in a single test function. Ideally each function should only test one thing. That way when the test fails you know exactly what is wrong. Instead of initializing test data in the test function, you can write fixtures. Each fixture can be used in multiple test functions. You don't need to assert '...


Top 50 recent answers are included