CodeSampleX

サンプル

gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c: check.DeepEquals

検証済みサンプル — golang gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c: check.DeepEquals. go 1.26 · linux debian/x64 · docker で contract を実行し、成功しました.

sha256:8d99e3d243252623adf34e83f60ff1d5420ec411de3b80fb2091d87a49886ffa

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 go

検証実行環境

環境 コントラクト ステージ 実行日
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-03

ケース

HOW
ゴール
verify pkg:golang/gopkg.in/check.v1@v1.0.0-20201130134442-10cb98267c6c
パッケージ
シンボル
  • check.DeepEquals
作成日
2026-09-03T05:36:59Z

コントラクト

  1. check.DeepEquals verifies deep structural equality between composite types including slices, maps, and structs
  2. check.DeepEquals detects differences when elements, field values, or ordering mismatch
  3. check.DeepEquals exposes CheckerInfo naming DeepEquals with obtained and expected parameters
  4. check.DeepEquals integrates with check.C Assert and Check to validate nested data structures in test suites

ファイル

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • sample.go
  • spec.json
  • test/contract.go

ソースアーティファクトをダウンロード (tar.gz)

ソース

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify pkg:golang/gopkg.in/check.v1@v1.0.0-20201130134442-10cb98267c6c
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/gopkg.in/check.v1@v1.0.0-20201130134442-10cb98267c6c

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:13e5319e07128df323ea0f47c31ab36bb44c990984b9691ccdad9bf4e0219bc8","contract":["check.DeepEquals verifies deep structural equality between composite types including slices, maps, and structs","check.DeepEquals detects differences when elements, field values, or ordering mismatch","check.DeepEquals exposes CheckerInfo naming DeepEquals with obtained and expected parameters","check.DeepEquals integrates with check.C Assert and Check to validate nested data structures in test suites"],"goal":"verify pkg:golang/gopkg.in/check.v1@v1.0.0-20201130134442-10cb98267c6c","kind":"HOW","packages":["pkg:golang/gopkg.in/check.v1@v1.0.0-20201130134442-10cb98267c6c"],"schemaVersion":1,"symbols":["check.DeepEquals"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/gopkg.in/check.v1@v1.0.0-20201130134442-10cb98267c6c"],"schemaVersion":1,"subject":"pkg:golang/gopkg.in/check.v1@v1.0.0-20201130134442-10cb98267c6c","symbols":["check.DeepEquals"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require (
	github.com/kr/pretty v0.2.1 // indirect
	github.com/kr/text v0.1.0 // indirect
	gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
)
go.sum
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
sample.go
package sample

import (
	"gopkg.in/check.v1"
)

// UserProfile represents user information with nested structures and collections.
type UserProfile struct {
	ID       int
	Username string
	Roles    []string
	Metadata map[string]string
}

// UserProfileSuite tests UserProfile operations using gopkg.in/check.v1 DeepEquals.
type UserProfileSuite struct {
	DefaultProfile UserProfile
}

// SetUpSuite initializes the test suite fixture.
func (s *UserProfileSuite) SetUpSuite(c *check.C) {
	s.DefaultProfile = UserProfile{
		ID:       1,
		Username: "admin",
		Roles:    []string{"read", "write"},
		Metadata: map[string]string{"env": "production"},
	}
}

// TestDeepEqualsProfile tests that identical user profiles pass DeepEquals assertion.
func (s *UserProfileSuite) TestDeepEqualsProfile(c *check.C) {
	clone := UserProfile{
		ID:       1,
		Username: "admin",
		Roles:    []string{"read", "write"},
		Metadata: map[string]string{"env": "production"},
	}
	c.Assert(clone, check.DeepEquals, s.DefaultProfile)
}

// TestDeepEqualsSlice tests slice comparison with DeepEquals.
func (s *UserProfileSuite) TestDeepEqualsSlice(c *check.C) {
	roles := []string{"read", "write"}
	c.Check(s.DefaultProfile.Roles, check.DeepEquals, roles)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/gopkg.in/check.v1@v1.0.0-20201130134442-10cb98267c6c",
  "kind": "HOW",
  "packages": [
    "pkg:golang/gopkg.in/check.v1@v1.0.0-20201130134442-10cb98267c6c"
  ],
  "symbols": [
    "check.DeepEquals"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"gopkg.in/check.v1"
	"sample"
)

func main() {
	// 1. check.DeepEquals verifies deep structural equality between composite types including slices, maps, and structs
	sliceA := []string{"alpha", "beta", "gamma"}
	sliceB := []string{"alpha", "beta", "gamma"}
	matchSlice, errStr := check.DeepEquals.Check([]interface{}{sliceA, sliceB}, []string{"obtained", "expected"})
	if !matchSlice || errStr != "" {
		fmt.Fprintf(os.Stderr, "DeepEquals failed on identical slices: %s\n", errStr)
		os.Exit(1)
	}

	mapA := map[string]int{"cpu": 4, "memory": 16}
	mapB := map[string]int{"cpu": 4, "memory": 16}
	matchMap, errStr := check.DeepEquals.Check([]interface{}{mapA, mapB}, []string{"obtained", "expected"})
	if !matchMap || errStr != "" {
		fmt.Fprintf(os.Stderr, "DeepEquals failed on identical maps: %s\n", errStr)
		os.Exit(1)
	}

	structA := sample.UserProfile{
		ID:       101,
		Username: "operator",
		Roles:    []string{"admin"},
		Metadata: map[string]string{"region": "us-west"},
	}
	structB := sample.UserProfile{
		ID:       101,
		Username: "operator",
		Roles:    []string{"admin"},
		Metadata: map[string]string{"region": "us-west"},
	}
	matchStruct, errStr := check.DeepEquals.Check([]interface{}{structA, structB}, []string{"obtained", "expected"})
	if !matchStruct || errStr != "" {
		fmt.Fprintf(os.Stderr, "DeepEquals failed on identical structs: %s\n", errStr)
		os.Exit(1)
	}

	// 2. check.DeepEquals detects differences when elements, field values, or ordering mismatch
	diffSlice := []string{"gamma", "beta", "alpha"}
	diffSliceMatch, _ := check.DeepEquals.Check([]interface{}{sliceA, diffSlice}, []string{"obtained", "expected"})
	if diffSliceMatch {
		fmt.Fprintf(os.Stderr, "DeepEquals incorrectly matched slices with differing order\n")
		os.Exit(1)
	}

	diffFieldStruct := sample.UserProfile{
		ID:       102,
		Username: "operator",
		Roles:    []string{"admin"},
		Metadata: map[string]string{"region": "us-west"},
	}
	diffStructMatch, _ := check.DeepEquals.Check([]interface{}{structA, diffFieldStruct}, []string{"obtained", "expected"})
	if diffStructMatch {
		fmt.Fprintf(os.Stderr, "DeepEquals incorrectly matched structs with different ID\n")
		os.Exit(1)
	}

	diffMap := map[string]int{"cpu": 4, "memory": 32}
	diffMapMatch, _ := check.DeepEquals.Check([]interface{}{mapA, diffMap}, []string{"obtained", "expected"})
	if diffMapMatch {
		fmt.Fprintf(os.Stderr, "DeepEquals incorrectly matched maps with different values\n")
		os.Exit(1)
	}

	// 3. check.DeepEquals exposes CheckerInfo naming DeepEquals with obtained and expected parameters
	info := check.DeepEquals.Info()
	if info == nil {
		fmt.Fprintf(os.Stderr, "expected non-nil CheckerInfo from DeepEquals\n")
		os.Exit(1)
	}
	if info.Name != "DeepEquals" {
		fmt.Fprintf(os.Stderr, "expected checker name DeepEquals, got %s\n", info.Name)
		os.Exit(1)
	}
	if len(info.Params) != 2 || info.Params[0] != "obtained" || info.Params[1] != "expected" {
		fmt.Fprintf(os.Stderr, "unexpected params in CheckerInfo: %v\n", info.Params)
		os.Exit(1)
	}

	// 4. check.DeepEquals integrates with check.C Assert and Check to validate nested data structures in test suites
	suite := &sample.UserProfileSuite{}
	check.Suite(suite)
	conf := &check.RunConf{}
	result := check.Run(suite, conf)
	if result == nil {
		fmt.Fprintf(os.Stderr, "expected non-nil Run result\n")
		os.Exit(1)
	}
	if !result.Passed() {
		fmt.Fprintf(os.Stderr, "test suite failed: %s\n", result.String())
		os.Exit(1)
	}
	if result.Succeeded < 2 {
		fmt.Fprintf(os.Stderr, "expected at least 2 succeeded tests, got %d\n", result.Succeeded)
		os.Exit(1)
	}

	fmt.Println("All gopkg.in/check.v1 DeepEquals contract assertions passed.")
}

オリジンシーダー

匿名