MT2 Flashcards
What are documentation comments?
- comment statements that use triple forward slashes (///) and XML formatted comment body
- must precede a user-defined type / member
What is an XML
Extensible Markup Language
- readable to both human and machines
- uses tags ex. < summary> and </ summary>
what is the tag: <summary>
- brief info abt type / type member (appears as first comment)
what is the tag: <param></param>
- describe method parameters
ex. <param></param> First addition operand. </param> - DON’T include type in parameter
what is the tag: <return></return>
describe return value of method
what is the tag: <exception></exception>
inform that the method can throw specific exceptions.
<exception>
</exception>
What is Unit Testing?
process of testing program components (methods / object classes)
- automatically test all units
How does unit testing distinguish class from method
By using attributes
class –> [TestClass()]
method –> [TestMethods()]
What is the pattern of a unit test
- Arrange
- initalize and select test case - Act
- call method to be tested - compare result of call with expected result
How to write a unit test that expects an exception?
use attribute –>
[ExpectedException(typeof(“insert specific exception”)]
What is an exception?
Runtime error –>
1. program violates system / application contstraint
2. There is a condition that is not normally expected
4 types of exception Handling
- corrective actions
- log information about error
- clean up before terminating
(ex. closing files) - Display error message before terminating
3 components of Try/ Catch Statements
- Try Block:
Contains statements being guarded for exceptions (ex. statements that might throw an exception) - Catch Clause:
Contains exception handlers - Finally Block
Contains code to be executed (whether or not exception is thrown)
2 common forms of Catch Statement
- catch( ExceptionType)
- matches any exception of the named type - catch (ExceptionType, ExceptionVariable)
- identifier (second parameter) acts as local variable and references exception object (used to access info about object)
Two Main Types of Exceptions
- SystemException
- base class for exceptions in C# base library
2.ApplicationException
- programmers create own exception classes
What is a specification?
description of what a type or a type member does
- may apply to entire programs, or functions/methods
also describes preconditions and postconditions
constrains (input) domain and (output) range of a method
Benefits of Specifications
Acts as a contract between implementer and consumer/client
Implementer:
- freedom to change implementation
- easier to determine errors
Consumer/ client:
- use methods without reading code
- describe how to ensure you get expected result
What is a precondition
(“requires”)
- a condition that must be true in order for implementation to work
- if not true, behaviour is undefined (exceptions, crashses, infinite loops)
What is a postcondition
(“effects” or “returns”)
- what the implementer of method promises to do
- often states what it returns
What is a frame condition
- identifies which objects may be modified
(therefore implicitly tells which object is not modified) - if omitted: nothing is modified
How to compare specifications
Strong specifications:
1. Weak preconditions
(fewer demands)
- Strong postconditions
(more promises)
Deterministic Vs. Under-determined
Determinisitic:
- when preconditions are met, outcome is clearly defined
(ex. when 13 appears in an array exactly once, return index of that array)
Under-determined:
- has vague preconditions, outcome is not clearly defined
(ex. when 13 appears in array, return index of that array… what if 13 appears more than once?)
Declarative Vs. Operational
Declarative:
- no details of intermediate steps
Operational
- gives series of steps that method performs (ex. pseudocode)
Characteristics of Good Specification
- Be coherent
- Not too strong / not too weak
- Uses abstract types when possible
- informative on results of a call
What is a set
- datatype where elements can be added or removed
- we can check if element is in a set or not
2 characteristics:
1. unordered
2. no duplicates
What is HashSet<T></T>
Represents a set (unordered and unique) of values
Parameter T can be anything
Mathematical set operations (HashSet<T> Methods)</T>
- IntersectWith
modified HashSet to contain elements present in object + specified collection
(contains only common elements) - UnionWith
modified HashSet to contain all elements in itself, a specified collection or both
(“appends” new unique elements) - IsSubsetOf:
determines if HashSet is a subset of a specified collection - SymmetricExceptWith
modifies current HashSet object to contain elements present either in itself or specified collection but not both
(contains non-common elements)
3 types of Software Validation
validation: process of checking that software conforms to its specifications
- Testing
running program on test cases - Code review
have another person read and verify code correctness - Formal reasoning (verification)
construct formal proof that program is correct
3 Reasons why Software Testing is Hard :(
- Exhaustive testing
- takes up a lot of space (infeasible) - Haphazard Testing
- unreliable and doesn’t help much - Statistical testing
doesn’t work on software
What is a test suite
collection of tests
–> increases change of finding bugs
BlackBox Vs WhiteBox
BlackBox:
choose test cases only from specs
(implementation of method is not known/ considered by tester)
WhiteBox:
choose test cases based on knowledge of method implementation
(you know how the code runs)
3 types of coverage
Coverage: judge if test suite thoroughly exercises program
- Statement coverage:
is every statement run by a test case? - Branch coverage:
for every if or while statement –> are both true and false directions considered? - Path coverage:
is every path of the program considered
(often combination of both statement and branch)
What is Partitioning
divide input space into subdomains
- each subdomain covers sets of similar input on which program has similar behavior
- consider special / corner cases
ex. method that takes deriviative of (1/x)
partition test cases into:
1. negative x values
2. positive x values
3. at or around x = 0
What are local functions?
function that is declared inside a method
(can only be called from the method containing it)
- local functions CANNOT include member access modifiers (e.g private or public)
- normally paced at beginning of method or anywhere in the method where it is in scope
Benefit of local functions?
Remember: method is function member of class / type
Local functions allows for…
Modularity:
- describes meaningful operation / behavior for intended class / type
3 Version Control Types
- Local
- keeping different versions of code file that is independently being worked on - Centralized version
- central sever contains repository (has all versioned files and history records)
- multiple users can collaborate and obtain copy of latest snapshot of files - Distributed version
- each user obtains full copy of repository from server
- easier and efficient collaboration
What is Github?
Distributed version control tool
(for text-based documents / code)
- keeps track of snapshots at any point
- server used with git version control (remote copy of repository is kept)
- all users has access to remote repository (can obtain full mirror of repository, history, or push to remote repository)
Github Terminology: Repository
storage space for project files and history
Github Terminology: Head
Current version in Git history snapshots
Github Terminology: Main
default branch name
Github Terminology: Remote
github repository (or any remote server used for distributed version control)
What is a delegate?
Application: passing method as an argument of another method
ex. (public delegate double Function(double x))
Keyword: var
shorthand for type that can be inferred from initialization
var list = new List<char>(new char...)</char>
- vars are better used for constructors
- NOT a type (just a syntactic shorthand)
- only used with local variables
Target-typed
if target type of an expression is known, type name can be omitted
Ex.
List<int> list 1 = new();</int>
instead of
List<int> list1 = new List<int>();</int></int>
(CANNOT be used with var keyword)
Keyword: in
used for method parameter
- argument must be initialized before passed in method call
- method CANNOT modify argument with “in” keyword
ex. foreach (var item in list)
Keyword: out
return more than one variable from a method
- all “out” arguments must be modified and observed by calling method
- must use “out” in method call
Keyword: ref
pass an argument by reference
- similar to “out” except, just like “in”, variable must be initialized before being passed
- must use “ref” in method call
Pass-by-value vs Pass by Reference
Pass-by-value
passing copy of variable to method
- changes to parameter does not change original data stored in argument
ex. (pass reference type by value)
- original reference is not changed but whatever it is referring to can be changed
Pass-by Reference
reference to original data is passed
- changes to parameter changes original data
ex. (pass value type by ref)
- use “ref” or “out”
- “in” also passes by reference but does not allow modification
Class type
user-define reference type
passed by value
- method receives copy of reference to class instance (receives copy of address of instance)
- method can use copy to access class members (that both og address and copy references)
- therefore, when a method changes a class member, the original class instance also changes