CodeSampleX

サンプル

github.com/beorn7/perks v1.0.1: quantile.Samples

検証済みサンプル — golang github.com/beorn7/perks v1.0.1: quantile.Samples. go 1.26 · linux debian/x64 · docker で contract を実行し、成功しました.

sha256:82a944be7a5f9d6be7df33c67e0e20238a88d4d590a2869e0158c5bf6b5c5446

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。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-06

ケース

HOW
ゴール
verify github.com/beorn7/perks/quantile.Samples in pkg:golang/github.com/beorn7/perks@v1.0.1
パッケージ
シンボル
  • github.com/beorn7/perks/quantile.Samples
作成日
2026-09-06T04:38:22Z

コントラクト

  1. quantile.Samples represents a slice of Sample items containing Value, Width, and Delta
  2. quantile.Samples implements sort.Interface methods Len, Less, and Swap
  3. sort.Sort reorders quantile.Samples in ascending order by Value
  4. sort.IsSorted validates sorted order of quantile.Samples
  5. Stream.Samples returns a quantile.Samples slice representing retained stream observations

ファイル

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.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 github.com/beorn7/perks/quantile.Samples in pkg:golang/github.com/beorn7/perks@v1.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/beorn7/perks@v1.0.1
Demonstrate these symbols/APIs:
  - github.com/beorn7/perks/quantile.Samples

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:5dbaa8ded5387644f2e179bd90544a22926e005b073e7c97555eefeaf3b45977","contract":["quantile.Samples represents a slice of Sample items containing Value, Width, and Delta","quantile.Samples implements sort.Interface methods Len, Less, and Swap","sort.Sort reorders quantile.Samples in ascending order by Value","sort.IsSorted validates sorted order of quantile.Samples","Stream.Samples returns a quantile.Samples slice representing retained stream observations"],"goal":"verify github.com/beorn7/perks/quantile.Samples in pkg:golang/github.com/beorn7/perks@v1.0.1","kind":"HOW","packages":["pkg:golang/github.com/beorn7/perks@v1.0.1"],"schemaVersion":1,"symbols":["github.com/beorn7/perks/quantile.Samples"]},"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/github.com/beorn7/perks@v1.0.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/beorn7/perks@v1.0.1","symbols":["github.com/beorn7/perks/quantile.Samples"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/beorn7/perks v1.0.1
go.sum
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
main.go
package main

import (
	"fmt"
	"sort"

	"github.com/beorn7/perks/quantile"
)

func main() {
	// Construct a quantile.Samples slice directly
	samples := quantile.Samples{
		{Value: 42.0, Width: 1.0, Delta: 0.0},
		{Value: 10.5, Width: 1.0, Delta: 0.0},
		{Value: 99.9, Width: 2.0, Delta: 0.0},
		{Value: 3.14, Width: 1.0, Delta: 0.0},
	}

	fmt.Printf("Initial samples count: %d\n", samples.Len())
	fmt.Printf("Is sorted initially: %v\n", sort.IsSorted(samples))

	// Sort samples using standard library sort.Sort
	sort.Sort(samples)
	fmt.Printf("Is sorted after sort.Sort: %v\n", sort.IsSorted(samples))
	for i, s := range samples {
		fmt.Printf("Sample %d: Value=%.2f Width=%.1f Delta=%.1f\n", i, s.Value, s.Width, s.Delta)
	}

	// Obtain quantile.Samples from an active Stream
	stream := quantile.NewTargeted(map[float64]float64{0.50: 0.01, 0.90: 0.01})
	for i := 1; i <= 100; i++ {
		stream.Insert(float64(i))
	}

	streamSamples := stream.Samples()
	fmt.Printf("Stream retained samples count: %d\n", streamSamples.Len())
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/beorn7/perks/quantile.Samples in pkg:golang/github.com/beorn7/perks@v1.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/beorn7/perks@v1.0.1"
  ],
  "symbols": [
    "github.com/beorn7/perks/quantile.Samples"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"sort"

	"github.com/beorn7/perks/quantile"
)

func main() {
	// Assertion 1: quantile.Samples represents a slice of Sample items containing Value, Width, and Delta
	{
		s := quantile.Samples{
			{Value: 15.5, Width: 1.0, Delta: 0.0},
			{Value: 3.2, Width: 2.0, Delta: 0.5},
		}
		if len(s) != 2 {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: expected length 2, got %d\n", len(s))
			os.Exit(1)
		}
		if s[0].Value != 15.5 || s[0].Width != 1.0 || s[0].Delta != 0.0 {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: unexpected sample values at index 0\n")
			os.Exit(1)
		}
		if s[1].Value != 3.2 || s[1].Width != 2.0 || s[1].Delta != 0.5 {
			fmt.Fprintf(os.Stderr, "assertion 1 failed: unexpected sample values at index 1\n")
			os.Exit(1)
		}
	}

	// Assertion 2: quantile.Samples implements sort.Interface methods Len, Less, and Swap
	{
		var _ sort.Interface = quantile.Samples{}
		s := quantile.Samples{
			{Value: 50.0, Width: 1.0, Delta: 0.0},
			{Value: 20.0, Width: 1.0, Delta: 0.0},
			{Value: 80.0, Width: 1.0, Delta: 0.0},
		}
		if s.Len() != 3 {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: expected Len() == 3, got %d\n", s.Len())
			os.Exit(1)
		}
		if s.Less(0, 1) {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: expected Less(0, 1) to be false (50 < 20)\n")
			os.Exit(1)
		}
		if !s.Less(1, 0) {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: expected Less(1, 0) to be true (20 < 50)\n")
			os.Exit(1)
		}
		s.Swap(0, 1)
		if s[0].Value != 20.0 || s[1].Value != 50.0 {
			fmt.Fprintf(os.Stderr, "assertion 2 failed: Swap did not swap elements correctly\n")
			os.Exit(1)
		}
	}

	// Assertion 3: sort.Sort reorders quantile.Samples in ascending order by Value
	{
		s := quantile.Samples{
			{Value: 45.0, Width: 1.0, Delta: 0.0},
			{Value: 12.0, Width: 2.0, Delta: 0.1},
			{Value: 99.0, Width: 1.0, Delta: 0.0},
			{Value: 5.5, Width: 1.0, Delta: 0.0},
			{Value: 33.3, Width: 3.0, Delta: 0.2},
		}
		sort.Sort(s)
		for i := 1; i < len(s); i++ {
			if s[i-1].Value > s[i].Value {
				fmt.Fprintf(os.Stderr, "assertion 3 failed: not sorted at index %d (%f > %f)\n", i, s[i-1].Value, s[i].Value)
				os.Exit(1)
			}
		}
		if s[0].Value != 5.5 || s[len(s)-1].Value != 99.0 {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: unexpected min/max after sort: min=%f, max=%f\n", s[0].Value, s[len(s)-1].Value)
			os.Exit(1)
		}
	}

	// Assertion 4: sort.IsSorted validates sorted order of quantile.Samples
	{
		unsorted := quantile.Samples{
			{Value: 10.0},
			{Value: 5.0},
		}
		if sort.IsSorted(unsorted) {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: unsorted samples reported as sorted\n")
			os.Exit(1)
		}
		sorted := quantile.Samples{
			{Value: 1.0},
			{Value: 2.0},
			{Value: 3.0},
		}
		if !sort.IsSorted(sorted) {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: sorted samples reported as unsorted\n")
			os.Exit(1)
		}
	}

	// Assertion 5: Stream.Samples returns a quantile.Samples slice representing retained stream observations
	{
		stream := quantile.NewTargeted(map[float64]float64{0.50: 0.01})
		for i := 1; i <= 200; i++ {
			stream.Insert(float64(i))
		}
		var samples quantile.Samples = stream.Samples()
		if len(samples) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: expected non-empty samples from stream\n")
			os.Exit(1)
		}
		for _, sample := range samples {
			if sample.Value < 1.0 || sample.Value > 200.0 {
				fmt.Fprintf(os.Stderr, "assertion 5 failed: sample value %f out of range [1, 200]\n", sample.Value)
				os.Exit(1)
			}
			if sample.Width <= 0 {
				fmt.Fprintf(os.Stderr, "assertion 5 failed: expected positive sample width, got %f\n", sample.Width)
				os.Exit(1)
			}
		}
	}

	fmt.Println("All contract assertions passed successfully.")
}

オリジンシーダー

匿名