Skip to content

Instantly share code, notes, and snippets.

@hasandiwan
Created March 12, 2026 09:03
Show Gist options
  • Select an option

  • Save hasandiwan/7fceb90e0561d72a7ddc56e312376ed9 to your computer and use it in GitHub Desktop.

Select an option

Save hasandiwan/7fceb90e0561d72a7ddc56e312376ed9 to your computer and use it in GitHub Desktop.
chatautism.net #investing test code
import app
import io
import json
import numpy as np
import pandas as pd
import pytest
def test_stock():
resp = app.stock()
assert all([k in resp for k in ["title", "data", "time"]])
assert resp.get("time") > 0
frame = pd.read_json(io.StringIO(resp.get("data")))
assert frame.index.dtype == '<M8[us]'
assert frame.Close.dtype == np.float64
assert frame.Interpolated.dtype == bool
def test_stock_with_custom_column():
resp = app.stock({"column": "Open"})
frame = pd.read_json(io.StringIO(resp.get("data")))
assert 'Open' in frame.columns
assert frame.Open.dtype == np.float64
def test_stock_currency_name_full_country_name():
resp = app.stock({"sym": "USD/ILS"})
frame = json.loads(resp)
assert frame.get('title') == "US Dollar/New Israeli Sheqel"
def test_stock_multiple_days():
resp = app.stock({"days": 2})
frame = pd.read_json(io.StringIO(resp.get("data")))
assert frame.iloc[-1*2,-1]
def test_kmeans_with_guesses():
book = [[1.9, 2.3], [0.8, 0.6]]
whitened = [
[1.9, 2.3],
[1.5, 2.5],
[0.8, 0.6],
]
response = app.kmeans({"rng": 5432})
assert all([k in response for k in ["observations", "numClusters", "time"]])
assert response.get("time") > 0
assert response.get("numClusters") == 2
assert response.get("observations") == [
[3.73950143, 2.81542279],
[1.75976538, 0.7038557],
]
assert response.get("distancesMean") == 0.3035419465698511
def test_kmeans_with_cluster_count():
book = [[1.9, 2.3], [0.8, 0.6]]
whitened = [
[1.9, 2.3],
[1.5, 2.5],
[0.8, 0.6],
]
response = app.kmeans({"rng": 5432})
assert response.get("numClusters") == 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment