## Random Ruby

- the
`chr`

and*ord*methods deal with integer ordinals of one character strings, the built in version of the OTP code I wrote, but without wrap around capability

## Testing with RSpec

- Level 2
- Rails: include rspec in gemfile (development/test group), bundle install,
`rails generate r`

*spec:install*- Rails spec helper is unique
- requires helper files within
`spec/support/`

- allows you to change default configuration with a configure block (change mocking and stubbing? mocha?)

- requires helper files within
- Can put options like
`--color`

and`--format documentation`

within the`.rspec`

file to make them defaults - can specify line number when running
`:4`

- Rails spec helper is unique
- matchers
- .
`match`

with regex `include`

`.have(number).thing_to_have (_at_least`

or`_at_most`

suffixes)`.from(num)`

to`.to(num)`

`respond_to(method_name)`

,`be_within(range).of(value), exist, satisfy {block_returns_true}, be_kind_of(class), be_an_instance_of(class)`

*expect {block}.to change{fetched_attribute}.to change.from().to()*(works with`to`

and`should`

)

- .

- Rails: include rspec in gemfile (development/test group), bundle install,
- Level 3 – DRY tips
`respond_to`

checks for an instance method for an instance- if you start a block with:
`describe ClassName do`

(must start with a class), then when you use the keyword`subject`

inside an example, RSpec will insert`Zombie`

- but really, you can omit a word completely:
`subject.respond_to(:name) ==`

`respond_to(:name)`

- alternatively, you could explicitly state the subject of a spec with a block

- but really, you can omit a word completely:
- if you use an
`it`

block where you are checking the subject, you can use`its`

- after
`describe ClassName do`

`it { subject.name.should == "a" } == its(:name) { should == "a" }`

- also useful when using
`its`

in conjunction with an explicit*subject*

- also useful when using

- can put a string with
`its`

so that the string will be evaluated

- after
`context`

, use just like`describe`

when nesting- then can just declare a subject:
`subject { block }`

and follow up with examples without indentation

- then can just declare a subject:
- What if you want to have multiple subjects?
- make a subject-like variable:
`let(:var_name) { block }`

- a newer way: subject(:name) == subject { name }

- make a subject-like variable:
- RSpec only instantiates
`subjects`

and`lets`

during a spec that calls for that`subject/it,`

if you wanted to instantiate something every time no matter what:- could use
`let!`

- could use

## Math

- Expectation Value / Mean value:
- multiply each possibile value of
`X`

,`x`

by the probability of its occurrence,_{i}`p`

, and sum all these_{i}`N`

possible values of`X`

- when
`N`

is large, and`x`

_{i }values are closely spaced (`X`

varies continuously), the probability of finding an`X`

value between`x`

and`x +`

`dx`

is equal to`f(x)dx`

- probability density
`f(x)`

, i.e. distribution of probability (derivative of cumulative probability), times an infinitesimally small interval of`x`

values - integral of
`f(x)dx`

conveniently represents the probability for finding a value of X between the limits of integration

- probability density

- multiply each possibile value of

Algorithms

- Instructions take a constant amount of time to execute
- Assume that in this book’s RAM model, inputs of size
`n`

are represented by`c lg n`

bits- why?

- Theta n-squared: Θ(n
^{2}) is looking at the leading term of a worst case running time, concerned with the order of growth

Alternate sum solution

- number system
- base^index * 1st digit
- 123: base is 10 for decimal. 10^0 *1st digit *3, 10^1 *2, 10^2 * 1:
- if number system is 2: 2^0*3, 2^1*2, 2^3*1

Advertisements