Open main menu

CDOT Wiki β

Changes

OSD600 and DPS909 Winter 2018 Lab 4

4,795 bytes added, 22:43, 7 March 2018
Created page with "=Contributing to Open Standards= This week we're discussing open standards, and for our lab will try writing some tests for the JavaScript (ecmascript) standard. In order fo..."
=Contributing to Open Standards=

This week we're discussing open standards, and for our lab will try writing some tests for the JavaScript (ecmascript) standard.

In order for implementors of the standard to know if they've got any bugs, a comprehensive set of tests are necessary. These tests should be something that can be run by any and all JavaScript implementations (i.e., we don't Microsoft to have their tests, Google to have their tests, Mozilla to have their tests, etc. and not share with each other). JavaScript should work the same everywhere, no matter which implementation you us.

In this Lab you will gain experience doing the following:

* reading a language standard
* running a test suite
* identifying testable aspects of the standard
* writing tests
* sharing work using gist.github.com

==1. Running the Test Suite==

The language is specified in https://tc39.github.io/ecma262/, and its test suite is available at https://github.com/tc39/test262.

To run the tests on your computer using node.js, follow the steps listed in https://github.com/bterlson/test262-harness#test262-harness.

When you run the tests, do all the tests pass or do any of them fail for you?

==2. Become Familiar with Tests==

Read the docs at https://github.com/tc39/test262/blob/master/CONTRIBUTING.md, which cover things like [https://github.com/tc39/test262/blob/master/CONTRIBUTING.md#test-case-names naming], [https://github.com/tc39/test262/blob/master/CONTRIBUTING.md#test-case-style general layout], [https://github.com/tc39/test262/blob/master/CONTRIBUTING.md#test-environment assertions], [https://github.com/tc39/test262/blob/master/CONTRIBUTING.md#handling-errors-and-negative-test-cases error handling], etc.

Based on what you've just read, take a look at this test for [https://github.com/tc39/test262/blob/master/test/built-ins/String/prototype/toUpperCase/S15.5.4.18_A2_T1.js String.prototype.toUpperCase()]. See if you can make sense of the code and what it's testing.

==3. Array.reverse==

In JavaScript, Arrays can be reversed using the <code>reverse()</code> method. It is defined in the standard at https://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.reverse. Begin by reading the definition of steps in the spec.

What sort of things could you test with <code>Array.reverse</code>? Based on what you read above, what sort of things need to be true about how <code>Array.reverse</code> works? Try to write a few tests for things you just thought about, using what you learned in 2.

To add a new test, you can create new <code>.js</code> files underneath <code>test/</code>.

==4. Extending the Existing Tests==

There are actually tests written now. You can see them in [https://github.com/tc39/test262/tree/a62da2b4997767a78bb2834c4fbf4e598b0fc241/test/built-ins/Array/prototype/reverse the Array.prototype.reverse() tests]

There is a bug to improve these tests, based on things learned while writing the [https://github.com/tc39/test262/tree/a62da2b4997767a78bb2834c4fbf4e598b0fc241/test/built-ins/TypedArray/prototype/reverse TypedArray.prototype.reverse tests].

Take a look at the code for the [https://github.com/tc39/test262/tree/a62da2b4997767a78bb2834c4fbf4e598b0fc241/test/built-ins/TypedArray/prototype/reverse TypedArray.prototype.reverse tests] and compare it to what is happening in the [https://github.com/tc39/test262/tree/a62da2b4997767a78bb2834c4fbf4e598b0fc241/test/built-ins/Array/prototype/reverse Array.prototype.reverse() tests].

Can you figure out some things you could change (i.e., ideas to borrow from the other tests)? Try rewriting some of the tests for <code>Array.reverse</code> to do what you think might be better.

NOTE: you do '''not''' need to submit your tests. This lab is only about reading the spec and existing tests, and understanding how they work.

==3. Blog==

Write a blog post about your experience reading the spec and tests and trying to write new tests. Put any code that you wrote into a [https://gist.github.com/ gist] on GitHub (i.e., you don't need to do a pull request or submit them anywhere).

Please add a line for your blog in the following table:

{| class="wikitable"
! #
! Name
! Gist of test cases (URLs)
! Blog Post (URL)
|-
| 1
|
|
|
|-
| 2
|
|
|
|-
| 3
|
|
|
|-
| 4
|
|
|
|-
| 5
|
|
|
|-
| 6
|
|
|
|-
| 7
|
|
|
|-
| 8
|
|
|
|-
| 9
|
|
|
|-
| 10
|
|
|
|-
| 11
|
|
|
|-
| 12
|
|
|
|-
| 13
|
|
|
|-
| 14
|
|
|
|-
| 15
|
|
|
|-
| 16
|
|
|
|-
| 17
|
|
|
|-
| 18
|
|
|
|-
| 19
|
|
|
|-
| 20
|
|
|
|-
| 21
|
|
|
|-
| 22
|
|
|
|-
| 23
|
|
|
|-
| 24
|
|
|
|-
| 25
|
|
|
|-
| 26
|
|
|
|-
| 27
|
|
|
|-
| 28
|
|
|
|-
| 29
|
|
|
|-
| 30
|
|
|
|-
| 31
|
|
|
|-
| 32
|
|
|
|-
| 33
|
|
|
|-
| 34
|
|
|
|-
| 35
|
|
|
|-
| 36
|
|
|
|-
| 37
|
|
|
|-
| 38
|
|
|
|-
| 39
|
|
|
|-
| 40
|
|
|
|-