Skip to content

How do I write a test which has an array of structs ? #24219

Discussion options

You must be logged in to vote

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

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jorgeluismireles
Comment options

@allocgator
Comment options

Answer selected by allocgator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants