1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-10 00:09:06 +01:00
LeetCode/go/number-of-atoms_test.go
Matej Focko a718efd3d8
go: add «726. Number of Atoms»
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-07-14 22:36:19 +02:00

28 lines
767 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import "testing"
func _test_NumberOfAtoms(t *testing.T, input, expected string) {
result := countOfAtoms(input)
if result != expected {
t.Errorf("Expected %s for %s, but got: %s!", expected, input, result)
}
}
func Test_NumberOfAtoms_Easy(t *testing.T) {
_test_NumberOfAtoms(t, "H2", "H2")
_test_NumberOfAtoms(t, "O2", "O2")
_test_NumberOfAtoms(t, "HO", "HO")
_test_NumberOfAtoms(t, "H2O", "H2O")
_test_NumberOfAtoms(t, "H2SO4", "H2O4S")
}
func Test_NumberOfAtoms_Medium(t *testing.T) {
_test_NumberOfAtoms(t, "Mg(OH)2", "H2MgO2")
_test_NumberOfAtoms(t, "C6H5OH", "C6H6O")
_test_NumberOfAtoms(t, "C6H5CH3", "C7H8")
}
func Test_NumberOfAtoms_Hard(t *testing.T) {
_test_NumberOfAtoms(t, "K4(ON(SO3)2)2", "K4N2O14S4")
}