How To Write A Contract On A Microsoft System.Io (For Free)



Similar documents
Code Contracts User Manual

How To Write A Validator In Java 1.1.1

SPICE auf der Überholspur. Vergleich von ISO (TR) und Automotive SPICE

Tobias Flohre codecentric AG. Ein Standard für die Batch- Entwicklung JSR-352

Internationale Gute Praxis für den Umgang mit Baggergut

Copyright 2013 wolfssl Inc. All rights reserved. 2

Microsoft Certified IT Professional (MCITP) MCTS: Windows 7, Configuration ( )

Diese Liste wird präsentiert von. Netheweb.de

Central Release and Build Management with TFS. Christian Schlag

Martin Käser. Single Sign-on mit OpenSAML

Brazil Brésil Brasilien. Report Q193

Abstraction and Abstract Data Types

Thomas Rümmler AIT GmbH & Co. KG Christian Schlag AIT GmbH & Co. KG. Central Build and Release Management with TFS

Horizon 2020 Aktuelle Fragen Organisation von Forschungspolitik und Programmdurchführung

OXID Modul-Zertifizierung Bedingungen

SQL 2014 CTP1. Hekaton & CSI Version 2 unter der Lupe. Sascha Götz Karlsruhe, 03. Dezember 2013

Mit einem Auge auf den mathema/schen Horizont: Was der Lehrer braucht für die Zukun= seiner Schüler

RFC's und Internet- Drafts mit URN-Bezug in Zusammenhang mit der Definition von Namen. Nik Klever FB Informatik - FH Augsburg klever@fh-augsburg.

How To Manage Build And Release With Tfs 2013

Benutzerfreundlich, tiefe Betriebskosten und hohe Sicherheit. Warum sich diese Ziele nicht widersprechen müssen

repositor.io Simple Repository Management Jürgen Brunk München, 03/2015

Software Requirements, Version 2015_01_12

Get Instant Access to ebook Ellen Shop PDF at Our Huge Library ELLEN SHOP PDF. ==> Download: ELLEN SHOP PDF

APPLICATION SETUP DOCUMENT

Gurkensalat statt Spaghetticode. Stuttgarter Testtage 2013

Agile Software-Requirements: User Stories und (Vieles) mehr

Neues in SQL Server Evaluierung SQL Server 2016 CTP 3 für den BI Stack. Sascha Götz Inovex GmbH

Linux & Docker auf Azure

Financial Reinsurance with Applications in Life Reassurance

Application example AC500 Scalable PLC for Individual Automation Communication between AC500 and KNX network abb

Kurz-Einführung Python

(Meine) Wahrheit über. Symfony. Timon Schroeter.

Till Vollmer Geschäftsführer MindMeister

Technische Alternative elektronische Steuerungsgerätegesellschaft mbh. A-3872 Amaliendorf, Langestr. 124 Tel +43 (0)

IDENTIKEY FEDERATION SERVICES

LEHMAN BROTHERS SECURITIES N.V. LEHMAN BROTHERS (LUXEMBOURG) EQUITY FINANCE S.A.

1. Wenn der Spieler/die Spielerin noch keine IPIN hat, bitte auf den Button Register drücken

Upgrade-Preisliste. Upgrade Price List

First Environmental Comparison of Rail Transport

Echtzeit-Analyse von Social Media Daten mit Jedox und GPU-beschleunigten OLAP Datenbanken

Dokumentation über die Übernahme von. "GS-R-3" (The Management System for Facilities and Activities) "Sicherheitskriterien für Kernkraftwerke"

Marc Grote. OCSP / CRL Schlüssel Archivierung CA-Konsole Certutil PKI Health

Rainer Stropek software architects gmbh. Entwicklung modularer Anwendungen mit C# und dem Managed Extensibility Framework (MEF)

TBarCode.NET Barcodes in MS SQL Reporting Services

HP SAP. Where Development, Test and Operations meet. Application Lifecycle Management

SECTION 1: Identification of the substance/mixture and of the company/undertaking

Die SharePoint-Welt für den erfahrenen.net- Entwickler. Fabian Moritz MVP Office SharePoint Server

Information Systems 2

TIn 1: Lecture 3: Lernziele. Lecture 3 The Belly of the Architect. Basic internal components of the Pointers and data storage in memory

Registries: An alternative for clinical trials?

Microsoft Nano Server «Tuva» Rinon Belegu

LEARNING AGREEMENT FOR STUDIES

SEIDENADER MASCHINENBAU GMBH

Aktives Service-, Asset- und Lizenzmanagement mit Altiris

Transfers of securities to The Royal Bank of Scotland plc pursuant to Part VII of the UK Financial Services and Markets Act 2000 RBS plc

Windows HPC Server 2008 Deployment

Allgemeines Dienstmanagement Das MNM-Dienstmodell in Herleitung und Anwendungsmethodik

AGIL JA, ABER SICHER? , ANDREAS FALK, 34. SCRUM TISCH

TECHNISCHE INFORMATION NR. SI SERVICE INFORMATION NO. SI36-053

Exemplar for Internal Assessment Resource German Level 1. Resource title: Planning a School Exchange

ANMERKUNGEN ZUR SCHULARBEIT

Search Engines Chapter 2 Architecture Felix Naumann

PASS Deutschland e.v. Regionalgruppe Köln/Bonn/Düsseldorf

J2EE-Application Server

FDT for Mobile Devices

Successful Collaboration in Agile Software Development Teams

LANCOM VoIP USB Handset LANCOM Advanced VoIP Client

OpenSSL mit Delphi. Max Kleiner.

Programmieren von Schnittstellen für LiveCycle ES2-Modulen (November 2009)

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

NATIVE ADVERTISING, CONTENT MARKETING & CO. AUFBRUCH IN EIN NEUES GOLDENES ZEITALTER DES MARKETINGS?

AC500. Application Example. Scalable PLC for Individual Automation. Webserver Login Application Example With PM564-ETH. abb

Erste Schritte mit mysql. Der Umgang mit einer relationalen Datenbank

Cambridge English Prüfungszentrum Sachsen

The Management of Contract Claims and the Resolution of Disputes

Transforming and optimization of the supply chain to create value and secure growth and performance

Satzgliedstellung. Regel #4: Adverbien: Die Satzgliedstellung verändert sich nicht, wenn eine adverbiale Bestimmung vorausgeht.

Implementing a PKI Infrastructure with Windows Server 2008/2012

Building an Architecture Model Entwerfen Sie mit AxiomSys ein Kontextdiagramm, das folgendermaßen aussieht:

Bei Fragen zu dieser Änderung wenden Sie sich bitte an Ihren Kundenbetreuer, der Ihnen gerne weiterhilft.

Semantic Web. Semantic Web: Resource Description Framework (RDF) cont. Resource Description Framework (RDF) W3C Definition:

Transcription:

Vertragssicher Code Contracts unter.net Michael Wiedeking michael.wiedeking@mathema.de www.mathema.de N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 1

Der Wächter double sqrt(double x) { if (x < 0) { throw new IllegalArgumentException(); // Berechnung der Quadratwurzel N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 2

Vorbedingung double sqrt(double x) { assert (x 0); // Berechnung der Quadratwurzel N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 3

Nachbedingung double sqrt(double x) { double result = // Berechnung der Quadratwurzel assert (abs((result * result) x) < ε); assert (result 0); return result; N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 4

Vor- und Nachbedingungen void increment() { assert (this.i > 0); int old_i = i; this.i += 1; assert (this.i == old_i + 1); N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 5

Invarianten void f (double a, double b) { assert (this.v 0); this.v = this.v a + b; assert (this.v 0); N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 6

Beispiel: Code Contracts using System; using System.Diagnostics.Contracts; namespace ContractExample1 { class Rational { int numerator; int denominator; N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 7

Beispiel: Code Contracts public Rational(int n, int d) { Contract.Requires(d! = 0); this.numerator = n; this.denominator = d; N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 8

Beispiel Code Contracts public int Denominator { get { Contract.Ensures(Contract.Result<int>()!= 0); return this.denominator; N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 9

Beispiel Code Contracts [ContractInvariantMethod] protected void ObjectInvariant () { Contract.Invariant(this.denominator! = 0); N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 10

Vorbedingung n n Contract.Requires(x!= null); Contract.Requires<ArgumentNullException>(x!= null, "x"); N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 11

Vorbedingung double sqrt(double x) { if (x < 0) { throw new IllegalArgumentException(); if (x > 0) { throw new DegeneratedResultException(); // Berechnung der Quadratwurzel N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 12

Abgrenzung der Vorbedingungen double sqrt(double x) { if (x < 0) { throw new IllegalArgumentException(); Contract. EndContractBlock() if (x == 0) { throw new DegeneratedResultException(); // Berechnung der Quadratwurzel N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 13

Nachbedingung Contract.Ensures(this.value > 0); Contract.EnsuresOnThrow<T>(this.value == 0); Contract.Ensure(Contract.Result<int>() > 0); Contract.Ensures(Contract.OldValue(xs.Length) > xs.length) Aber n Nachbedingung muss berechenbar sein (xs!= null E) n Contract.Result<T>() und out-paramneter nicht in einer Contract.Old-Anweisung benutzt werden N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 14

Nachbedingung public void OutParam(out int x) { Contract.Ensures(Contract.ValueAtReturn(out x) == 0); x = 0; N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 15

Invarianten [ContractInvariantMethod] protected void ObjectInvariant() { Contract.Invariant(velocity > 0); Contract.Invariant(direction!= null); n n n nur nach Aufruf einer public-methode ggf. Aussetzen der Prüfung (reentrant) nicht bei finalize oder dispose N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 16

Annahmen f = createbyname("x"); Contract.Assert(f!= null) N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 17

Annahmen f = createbyname("x"); Contract.Assume(f!= null) N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 18

Bedingungen für Collections public void findmultiples<t>(ienumerable<t> collection) { Contract.Requires( Contract.ForAll(collection, (T x) => x!= null) ); N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 19

Bedingungen für Collections public int[] Squares() { Contract.Ensures( ); Contract.ForAll( 0, Contract.Result<int[]>().Length, i => Contract.Result<int[]>()[i] > 0 ) N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 20

Bedingungen für Collections n n n n Contract.ForAll Contract.Exists System.Linq.Enumable.All System.Linq.Enumable.Any N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 21

Schnittstellen [ContractClass(typeof(IFooContract))] interface IFoo { int Count { get; void Put(int value); N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 22

Schnittstellen [ContractClassFor(typeof(IFoo))] sealed class IFooContract : IFoo { int IFoo.Count { get { Contract.Ensures(Contract.Result<int>() >= 0); return default(int); void IFoo.Put(int value){ Contract.Requires(0 <= value); N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 23

Schnittstellen [ContractClassFor(typeof(IFoo))] sealed class IFooContract : IFoo { void IFoo.Put(int value){ IFoo this = this; Contract.Requires(value >= 0); Contract.Requires(this.Count < 10); N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 24

Abstrakte Klassen [ContractClass(typeof(FooContract))] abstract class Foo { public abstract int Count { get; public abstract void Put(int value); N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 25

Abstrakte Klassen [ContractClassFor(typeof(Foo))] abstract class FooContract : Foo { public override int Count { get { Contract.Ensures(Contract.Result<int>() >= 0); return default(int); public override void Put(int value){ Contract.Requires(value >= 0); N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 26

Referenzen n n Microsoft Corporation Code Contracts User Manual http://download.microsoft.com/download/c/2/7/ C2715F76-F56C-4D37-9231-EF8076B7EC13/userdoc.pdf Microsoft Research Code Contracts http://research.microsoft.com/en-us/projects/contracts/ N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 27

Fragen? Vielen Dank! vorname.nachname@mathema.de N3 Vertragssicher Michael Wiedeking Copyright 2010 MATHEMA Software GmbH 28