design-by-contract

Am I implementing this simple contract incorrectly?

假装没事ソ 提交于 2020-01-22 10:40:21
问题 This is my code: public class RegularPolygon { public int VertexCount; public double SideLength; public RegularPolygon(int vertexCount, double sideLength) { Contract.Requires(vertexCount >= 3); VertexCount = vertexCount; SideLength = sideLength; } [ContractInvariantMethod] private void RegularPolygonInvariants() { Contract.Invariant(VertexCount>=3); } } I have tried with both the Contract.Requires and Contract.Invariant methods to prevent the vertexCount variable from becoming less than or

Eiffel: is there a way to express a double implies clause in eiffel?

我们两清 提交于 2020-01-17 02:40:06
问题 Like double bind in psychology, is there a way to tell that one expression implies another and reversely? valid_last_error: attached last_error implies not attached last_success_message valid_last_success_message: attached last_success_message implies not attached last_error would be something like valid_last_error: attached last_error double_binded_not attached last_success_message which could be equivalent to valid_last_error: attached last_error never_with attached last_success_message T

Eiffel: is there a way to express a double implies clause in eiffel?

岁酱吖の 提交于 2020-01-17 02:40:06
问题 Like double bind in psychology, is there a way to tell that one expression implies another and reversely? valid_last_error: attached last_error implies not attached last_success_message valid_last_success_message: attached last_success_message implies not attached last_error would be something like valid_last_error: attached last_error double_binded_not attached last_success_message which could be equivalent to valid_last_error: attached last_error never_with attached last_success_message T

How to ensure that implementations of an interface have a connection string if they are backed by a database using code contracts

一曲冷凌霜 提交于 2020-01-06 08:49:16
问题 Imagine you've an interface like this: public interface IPersonManager { public void AddPerson(string name); } ...and an implementation which we'll going to call DefaultPersonManager . Let's say we want to be sure that any implementation of IPersonManager won't be able to give a null or empty string as argument of AddPerson(string name) . For that matter, we're going to implement a contract class as follows: [ContractClassFor(typeof(IPersonManager))] public abstract class

Microsoft.Contracts namespace

▼魔方 西西 提交于 2020-01-05 04:58:11
问题 For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts; ? 回答1: For using code contracts. 回答2: You can find the library here C:\Program Files\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\mscorlib.dll 来源: https://stackoverflow.com/questions/1679392/microsoft-contracts-namespace

Meaning of \old in ACSL post-conditions

六眼飞鱼酱① 提交于 2020-01-02 07:12:51
问题 I am a newbie user of Frama-C and have a few questions regarding assertions over pointers. Consider the C fragment below involving: two related data structures Data and Handle, s.t. Handle has a pointer to Data; a 'state' field in Data indicating whether some hypothetical operation has completed three functions: init(), start_operation() and wait(); a main() function using the above, and containing 6 assertions (A1-A6) Now, why is it that A5 and A6 cannot be asserted with the WP verifier (

Referencing `self` in `__old__` in PyContract constraints

跟風遠走 提交于 2019-12-25 02:19:37
问题 I'm working on writing some constraints for a class method using PyContract (not PyContracts). As a postcondition, I'd like to ensure that the memory address of the instance hasn't changed i.e. id(self) should be the same before and after calling the function. How can I do this with PyContract? I have the following (minimal) code: class Individual: def append(self, chrom): """ post: __old__.self is self len(__old__.self.chromosomes)+1 == len(self.chromosomes) self.chromosomes[-1] == chrom """

How to define IEnumerable behavior by contract?

主宰稳场 提交于 2019-12-23 12:53:37
问题 Consider this 2 methods that returns IEnumerable: private IEnumerable<MyClass> GetYieldResult(int qtResult) { for (int i = 0; i < qtResult; i++) { count++; yield return new MyClass() { Id = i+1 }; } } private IEnumerable<MyClass> GetNonYieldResult(int qtResult) { var result = new List<MyClass>(); for (int i = 0; i < qtResult; i++) { count++; result.Add(new MyClass() { Id = i + 1 }); } return result; } This code shows 2 different behaviors when calling some method of IEnumerable: [TestMethod]

How to define IEnumerable behavior by contract?

点点圈 提交于 2019-12-23 12:53:28
问题 Consider this 2 methods that returns IEnumerable: private IEnumerable<MyClass> GetYieldResult(int qtResult) { for (int i = 0; i < qtResult; i++) { count++; yield return new MyClass() { Id = i+1 }; } } private IEnumerable<MyClass> GetNonYieldResult(int qtResult) { var result = new List<MyClass>(); for (int i = 0; i < qtResult; i++) { count++; result.Add(new MyClass() { Id = i + 1 }); } return result; } This code shows 2 different behaviors when calling some method of IEnumerable: [TestMethod]

Argument Exceptions should be Unit Tested?

江枫思渺然 提交于 2019-12-23 12:01:06
问题 I know this question is pretty similar to others that have been posted before but I would like to discuss this topic in a proper way. Do you think that the "obvious" exception should be unit tested? With obvious exception I mean for example exceptions due to null arguments or empty strings or negative numbers in situations where we the business logic of our unit make us obvious that these exceptions will always be thrown at the beginning of our method(s) before any other operation. In other