How do I write a test which has an array of structs ? #24219
Answered
by
gchumillas
allocgator
asked this question in
Questions and Answers
-
How can I write the below Go code in V:
? |
Beta Was this translation helpful? Give feedback.
Answered by
gchumillas
Apr 15, 2025
Replies: 1 comment 2 replies
-
Not sure what you want to do. This is the way to write a test in V: // tests are located in "path/to/anydir/filename_test.v"
// test functions starts with "test_" prefix
fn test_unique_paths() {
items := [
struct {
description: '3 ways to go from the top left corner to the bottom right corner in a 3 x 2 grid'
rows: 3
cols: 2
ways: 5
}
struct {
description: '6 ways to go from the top left corner to the bottom right corner in a 3 x 3 grid'
rows: 3
cols: 3
ways: 6
}
]
for item in items {
assert item.ways == item.rows + item.cols
}
} Here is the example: https://play.vlang.io/p/4f7525f3c8 |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
allocgator
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not sure what you want to do. This is the way to write a test in V:
Here is the example: https://play.vlang.io/p/4f7525f3c8