Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I was able to make it generate code to generate MD5 hashes with test cases

The output I got

package main

import ( "crypto/md5" "fmt" "testing" )

func TestCalculateMd5(t testing.T) { tests := []struct { name string s string want string }{ { name: "empty string", s: "", want: "d41d8cd98f00b204e9800998ecf8427e", }, { name: "hello world", s: "hello world", want: "5eb63bbbe01eeed093cb22bb8f5acdc3", }, } for _, tc := range tests { t.Run(tc.name, func(t testing.T) { got := calculateMd5(tc.s) if got != tc.want { t.Errorf("got %q, want %q", got, tc.want) } }) } }

func calculateMd5(s string) string { return fmt.Sprintf("%x", md5.Sum([]byte(s))) }



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: