MT2 Flashcards

1
Q

What are documentation comments?

A
  • comment statements that use triple forward slashes (///) and XML formatted comment body
  • must precede a user-defined type / member
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an XML

A

Extensible Markup Language
- readable to both human and machines
- uses tags ex. < summary> and </ summary>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is the tag: <summary>

A
  • brief info abt type / type member (appears as first comment)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is the tag: <param></param>

A
  • describe method parameters
    ex. <param></param> First addition operand. </param>
  • DON’T include type in parameter
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is the tag: <return></return>

A

describe return value of method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what is the tag: <exception></exception>

A

inform that the method can throw specific exceptions.

<exception>
</exception>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Unit Testing?

A

process of testing program components (methods / object classes)
- automatically test all units

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How does unit testing distinguish class from method

A

By using attributes
class –> [TestClass()]
method –> [TestMethods()]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the pattern of a unit test

A
  1. Arrange
    - initalize and select test case
  2. Act
    - call method to be tested
  3. compare result of call with expected result
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to write a unit test that expects an exception?

A

use attribute –>
[ExpectedException(typeof(“insert specific exception”)]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an exception?

A

Runtime error –>
1. program violates system / application contstraint
2. There is a condition that is not normally expected

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

4 types of exception Handling

A
  1. corrective actions
  2. log information about error
  3. clean up before terminating
    (ex. closing files)
  4. Display error message before terminating
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

3 components of Try/ Catch Statements

A
  1. Try Block:
    Contains statements being guarded for exceptions (ex. statements that might throw an exception)
  2. Catch Clause:
    Contains exception handlers
  3. Finally Block
    Contains code to be executed (whether or not exception is thrown)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

2 common forms of Catch Statement

A
  1. catch( ExceptionType)
    - matches any exception of the named type
  2. catch (ExceptionType, ExceptionVariable)
    - identifier (second parameter) acts as local variable and references exception object (used to access info about object)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Two Main Types of Exceptions

A
  1. SystemException
    - base class for exceptions in C# base library

2.ApplicationException
- programmers create own exception classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a specification?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Benefits of Specifications

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is a precondition

A

(“requires”)
- a condition that must be true in order for implementation to work
- if not true, behaviour is undefined (exceptions, crashses, infinite loops)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is a postcondition

A

(“effects” or “returns”)
- what the implementer of method promises to do
- often states what it returns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is a frame condition

A
  • identifies which objects may be modified
    (therefore implicitly tells which object is not modified)
  • if omitted: nothing is modified
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How to compare specifications

A

Strong specifications:
1. Weak preconditions
(fewer demands)

  1. Strong postconditions
    (more promises)
22
Q

Deterministic Vs. Under-determined

A

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?)

23
Q

Declarative Vs. Operational

A

Declarative:
- no details of intermediate steps

Operational
- gives series of steps that method performs (ex. pseudocode)

24
Q

Characteristics of Good Specification

A
  1. Be coherent
  2. Not too strong / not too weak
  3. Uses abstract types when possible
  4. informative on results of a call
25
Q

What is a set

A
  • 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

26
Q

What is HashSet<T></T>

A

Represents a set (unordered and unique) of values

Parameter T can be anything

27
Q

Mathematical set operations (HashSet<T> Methods)</T>

A
  1. IntersectWith
    modified HashSet to contain elements present in object + specified collection
    (contains only common elements)
  2. UnionWith
    modified HashSet to contain all elements in itself, a specified collection or both
    (“appends” new unique elements)
  3. IsSubsetOf:
    determines if HashSet is a subset of a specified collection
  4. SymmetricExceptWith
    modifies current HashSet object to contain elements present either in itself or specified collection but not both
    (contains non-common elements)
28
Q

3 types of Software Validation

A

validation: process of checking that software conforms to its specifications

  1. Testing
    running program on test cases
  2. Code review
    have another person read and verify code correctness
  3. Formal reasoning (verification)
    construct formal proof that program is correct
29
Q

3 Reasons why Software Testing is Hard :(

A
  1. Exhaustive testing
    - takes up a lot of space (infeasible)
  2. Haphazard Testing
    - unreliable and doesn’t help much
  3. Statistical testing
    doesn’t work on software
30
Q

What is a test suite

A

collection of tests

–> increases change of finding bugs

31
Q

BlackBox Vs WhiteBox

A

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)

32
Q

3 types of coverage

A

Coverage: judge if test suite thoroughly exercises program

  1. Statement coverage:
    is every statement run by a test case?
  2. Branch coverage:
    for every if or while statement –> are both true and false directions considered?
  3. Path coverage:
    is every path of the program considered
    (often combination of both statement and branch)
33
Q

What is Partitioning

A

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

34
Q

What are local functions?

A

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
35
Q

Benefit of local functions?

A

Remember: method is function member of class / type

Local functions allows for…
Modularity:
- describes meaningful operation / behavior for intended class / type

36
Q

3 Version Control Types

A
  1. Local
    - keeping different versions of code file that is independently being worked on
  2. 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
  3. Distributed version
    - each user obtains full copy of repository from server
    - easier and efficient collaboration
37
Q

What is Github?

A

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)
38
Q

Github Terminology: Repository

A

storage space for project files and history

39
Q

Github Terminology: Head

A

Current version in Git history snapshots

40
Q

Github Terminology: Main

A

default branch name

41
Q

Github Terminology: Remote

A

github repository (or any remote server used for distributed version control)

42
Q

What is a delegate?

A

Application: passing method as an argument of another method

ex. (public delegate double Function(double x))

43
Q

Keyword: var

A

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
44
Q

Target-typed

A

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)

45
Q

Keyword: in

A

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)

46
Q

Keyword: out

A

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
47
Q

Keyword: ref

A

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
48
Q

Pass-by-value vs Pass by Reference

A

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

49
Q

Class type

A

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
50
Q
A