leetcodeTests

package module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2023 License: MIT Imports: 16 Imported by: 0

README

自动生成LeetCode Go单元测试用例

用于基于 LeetCode 提供的示例自动生成单元测试用例。该工具目前并不能百分之百地支持所有题目,支持绝大部分数据类型但是不太普遍或没有返回值的问题无法自动生成单元测试。

功能

  • 基于 LeetCode 提供的示例自动生成 Go 单元测试用例
  • 能够自动生成超过 98% 的 LeetCode 题目的单元测试用例
  • 不能生成的题目包括环形单向链表和双向链表等

使用方法

  1. 快速安装
    go get github.com/king133134/leetcodeTests
    
  2. 进入 leetCodeTests 文件夹
  3. 有两种方式来生成测试用例,只需要提供题目的URL无论是.cn还是.com都支持
    1. 直接生成代码文件(推荐使用),下面命令就会在当前./tests目录生成对应的题目URL的单元测试用例
      go run example/main.go -mod=file -dir=./tests
      
      会提示你输入URL,如下图: 示例图片
    2. 通过网页表单表单交互生成
      go run example/main.go -mod=http -port=8080
      
      然后打开网址http://localhost:8080/index,输入题目URL即可
  4. 可以使用以下自定义方式
    1. 直接通过给URL和指定生成文件目录
      package main
      
      import "github.com/king133134/leetCodeTests"
      
      func main() {
         leetcodeTests.CreatByUrl("./tests", "https: //leetcode.cn/problems/brace-expansion-ii/")
      }
      
    2. 通过网页交互的方式,然后打开网址http://localhost:8080/index,输入题目URL即可
      package main
      
      import "github.com/king133134/leetCodeTests"
      
      func main() {
        leetcodeTests.HttpStart(8080)
      }
      

LICENSE

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreatAll

func CreatAll(dir string)

func CreatByUrl

func CreatByUrl(dir, url string)

func CreateById

func CreateById(dir, id string)

func FileRun

func FileRun(dir string)

func HttpStart

func HttpStart(port int)

HttpStart 用于创建HTTP服务器并启动它。它会将HTML模板加载到gin中,并注册两个处理函数Index和Question。

func Run

func Run(opts ...Option)

Types

type Option

type Option func(options *Options)

func Dir

func Dir(dir string) Option

func Mod

func Mod(mod string) Option

func Port

func Port(port int) Option

type Options

type Options struct {
	// contains filtered or unexported fields
}

type QuestionData

type QuestionData struct {
	// contains filtered or unexported fields
}

func Question

func Question(url string) *QuestionData

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL