Studying for open standard

In recent couple of classes, we learned about the standard of programming world. There're thousands of programmers in the world. All of them have different coding style. Before a language become a "language", it needs a "standard" so that the language developers can design it with those standard rules. That's why Java looks like this and Javascript looks like that.
But standard is not unchangeable. Programming world is developing fast. Many languages need to be upgrade too. In this lab, make "reverse" for example. Long time ago reverse is not a standard in Javascript language. Programmers want to reverse array so they designed this function and made it work without bug. They name it, use it again and again, fix all bugs they found. Then more and more programmers used it. Finally, it became standard in Javascript and many other language such as Java.
One of the way to find bugs is to write a tester. In this lab, we will test ECMA262. ECMA262 is a standard of Javascript. In this lab, we will read some test file written by others, and try writing test file by ourselves.

Test ECMA-262

To test ECMA-262, I followed this instruction: 
  https://github.com/bterlson/test262-harness#test262-harness
There're 205 tests built-in. 201 of them passed and 4 of them failed in my labtop(macOS High Sierra ver 10.13.3).

Anyway, keep going...

Let's take a look at test files folder:

Array.prototype.reverse:

Compare to
TypedArray.prototype.reverse:

TypedArray and Array are different things. So programmers wrote different tester for those. It seems like the tester for TypedArray is more perfect than Array tester.

Let's click and look at reverts.js in TypedArray tester. It looks like this:
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%typedarray%.prototype.reverse
description: Reverts values
info: |
22.2.3.22 %TypedArray%.prototype.reverse ( )

%TypedArray%.prototype.reverse is a distinct function that implements the same
algorithm as Array.prototype.reverse as defined in 22.1.3.21 except that the
this object's [[ArrayLength]] internal slot is accessed in place of performing
a [[Get]] of "length".

22.1.3.21 Array.prototype.reverse ( )

...
6. Return O.
includes: [testTypedArray.js, compareArray.js]
features: [TypedArray]
---*/

var buffer = new ArrayBuffer(64);

testWithTypedArrayConstructors(function(TA) {
var sample = new TA(buffer, 0, 4);
var other = new TA(buffer, 0, 5);

sample[0] = 42;
sample[1] = 43;
sample[2] = 2;
sample[3] = 1;
other[4] = 7;

sample.reverse();
assert(
compareArray(sample, [1, 2, 43, 42])
);

assert(
compareArray(other, [1, 2, 43, 42, 7])
);

sample[0] = 7;
sample[1] = 17;
sample[2] = 1;
sample[3] = 0;
other[4] = 42;

other.reverse();
assert(
compareArray(other, [42, 0, 1, 17, 7])
);

assert(
compareArray(sample, [42, 0, 1, 17])
);
});

My first impression of file content is:
1) The code is simple;
2) They very concern the information in head such as copyright, file description.

Base on this idea, I'm going to write a tester to test numbers array reversing and string array reversing.

 Here's link to my code:
https://gist.github.com/KignorChan/e82a9a597e2a02115238227e911ff1b5

Test result:

To try the test, put the .js file inside test folder, then run:

test262-harness test/*.js


Summary:

Writing test is not complex, but we need to make sure to deliver enough details in test file. That will let other know what kind of test exactly is, what relative resource is it.
Before writing the test, make sure to understand those function you we want to test. Like in this lab, we need to know what reverse is use for and how it work. We can read the documentation. Most of standard projects have documentations. Read it. Imagine what will happen, what results are expected to get. Then, we can start design the tests. 





Comments

Popular posts from this blog

OSD - Release 03

OSD600 - Lab 6: Fixing URL bug in Brave browser