Testing the stock account

Editing the balance: slot:

Testing the stock account

We can now test our stock account by asking for the balance, or setting the balance. However, there is a problem: we can set the balance so that we get a non-integral number of shares. Let's modify the balance: method so that it always rounds down to an integer. Clicking on the balance: slot's button exposes a text editor. We can then change the method body to read:

	numShares: b /- pricePerShare 

The /- method on numbers returns the result of division rounded down; /+ rounds up.

As soon as we change the text of the method, the green and red `counterfactual' bars appear. Whenever you see these bars in Self, they indicate that the associated item is `counterfactual', i.e., that it does not correspond to the `truth'. In this case, the text in the editor does not correspond to the source of the installed method. We can either make it truthful by clicking on the green bar (i.e., accepting it), or revert the view to the installed method, and discard our changes, by clicking the red bar.

After accepting the new version, we can test it.

[ Previous ] [ Index ] [ Next ]