Skip to content

Commit

Permalink
Update WaitGroup test to use 100 iterations
Browse files Browse the repository at this point in the history
No idea why its suddenly super slow

Also add the grammar file cos I forgot to
  • Loading branch information
JothamWong committed Apr 13, 2024
1 parent 3c86d5c commit d31d41f
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 58 deletions.
9 changes: 9 additions & 0 deletions src/parser/ooga.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Keyword
/ CaseToken
/ DefaultToken
/ SelectToken
/ AppendToken


Type
Expand Down Expand Up @@ -275,6 +276,7 @@ SwitchToken = "switch" !IdentifierPart
CaseToken = "case" !IdentifierPart
DefaultToken = "default" !IdentifierPart
SelectToken = "select" !IdentifierPart
AppendToken = "append" !IdentifierPart


SingleLineComment
Expand Down Expand Up @@ -391,6 +393,13 @@ CallExpression
args: args || []
};
}
/ AppendToken __ "(" __ name:Identifier __ "," __ args:ArgumentList __ ")" {
return {
tag: "AppendExpression",
name: name,
args: args
}
}

MakeArguments
= "," __ args:ArgumentList {
Expand Down
118 changes: 60 additions & 58 deletions src/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,64 +839,66 @@ v.X // 3

// Test WaitGroups

// testProgram(
// `
//
// type Vertex struct {
// X int
// }
//
// func (v *Vertex) Add(w Vertex) {
// v.X = v.X + w.X;
// }
//
// v := Vertex{1};
// w := Vertex{2};
//
// go func() {
// for i := 0; i < 1000; i++ { // iterate for 1000 times to prove that waitgroup works as intended
// }
// v.Add(w);
// }()
//
// v.X; //1
// `,
// 1,
// '',
// defaultNumWords
// );

// testProgram(
// `
//
// type Vertex struct {
// X int
// }
//
// func (v *Vertex) Add(w Vertex) {
// v.X = v.X + w.X;
// }
//
// v := Vertex{1};
// w := Vertex{2};
//
// wg := WaitGroup{1};
//
// go func() {
// for i := 0; i < 1000; i++ { // iterate for 1000 times to prove that waitgroup works as intended
// }
// v.Add(w);
// wg.Done();
// }()
//
// wg.Wait();
//
// v.X; //3
// `,
// 3,
// '',
// defaultNumWords
// );
testProgram(
`
type Vertex struct {
X int
}
func (v *Vertex) Add(w Vertex) {
v.X = v.X + w.X;
}
v := Vertex{1};
w := Vertex{2};
go func() {
for i := 0; i < 100; i++ { // iterate for 100 times to prove that waitgroup works as intended
}
v.Add(w);
}()
v.X; //1
`,
1,
'',
defaultNumWords
);

testProgram(
`
type Vertex struct {
X int
}
func (v *Vertex) Add(w Vertex) {
v.X = v.X + w.X;
}
v := Vertex{1};
w := Vertex{2};
wg := WaitGroup{1};
go func() {
for i := 0; i < 100; i++ { // iterate for 100 times to prove that waitgroup works as intended
}
v.Add(w);
wg.Done();
}()
wg.Wait();
v.X; //3
`,
3,
'',
defaultNumWords
);

// Testing struct methods with goroutines (goroutines cannot return anything)
testProgram(
Expand Down

0 comments on commit d31d41f

Please sign in to comment.